diff --git a/lib/classes/board.js b/lib/classes/board.js index 72a649b..f994ac9 100644 --- a/lib/classes/board.js +++ b/lib/classes/board.js @@ -84,14 +84,22 @@ GridGame.classes.board = function () { }; - this.place_random_rock = function() { + // TODO maybe move these two to an obstacle placing object + this.place_n_obstacles = function(flag_name, number) { + for(var i = number; i > 0; i--){ + this.place_random_obstacle(flag_name); + } + }; + + this.place_random_obstacle = function(flag_name) { var x = Math.floor(Math.random() * GridGame.width); var y = Math.floor(Math.random() * GridGame.height); var tile = this.tile(x, y); - if (tile.city || tile.rock) { - this.place_random_rock(); + if (tile.city || tile.rock || tile.wall) { + this.place_random_obstacle(flag_name); } else { - tile.rock = true; + tile[flag_name] = true; + tile.value = GridGame[flag_name + '_health']; } }; diff --git a/lib/classes/player.js b/lib/classes/player.js index 59939dc..293f491 100644 --- a/lib/classes/player.js +++ b/lib/classes/player.js @@ -2,7 +2,7 @@ GridGame.classes.player = function (config) { GridGame.player_components.control_panel.apply(this); GridGame.player_components.direction_change.apply(this); - + this.config = config; this.name = config.name; this.playable = config.playable; @@ -42,12 +42,14 @@ GridGame.classes.player = function (config) { var target_is_city = target.city; var target_already_stepped_to = target.changed_player; var target_is_rock = target.rock; + var target_is_wall = target.wall; // TODO and wall has health return ( target_present && (target_unowned || target_belongs_to_me) && !target_is_city && - !target_already_stepped_to && - !target_is_rock + !target_already_stepped_to && + !target_is_rock && + !target_is_wall ) }; diff --git a/lib/classes/tile.js b/lib/classes/tile.js index fcdad3c..1382893 100644 --- a/lib/classes/tile.js +++ b/lib/classes/tile.js @@ -10,6 +10,7 @@ GridGame.classes.tile = function (x, y) { this.value = 0; this.city = false; this.rock = false; + this.wall = false; // used in turn process this.value_change = 0; @@ -88,7 +89,8 @@ GridGame.classes.tile = function (x, y) { return (css.match(/\btile_\S+/g) || []).join(' '); }) .toggleClass('tile_city', this.city) - .toggleClass('tile_rock', this.rock); + .toggleClass('tile_rock', this.rock) + .toggleClass('tile_wall', this.wall); if (this.player && this.value > 0) { @@ -97,10 +99,12 @@ GridGame.classes.tile = function (x, y) { }; this.display_character = function () { - if (!this.player || this.value <= 0) { + if ((!this.player && !this.wall) || this.value <= 0) { return '' } else if (this.city) { return 'C' + this.value + ''; + } else if (this.wall) { + return '' + this.value + ''; } else { return this.value; } diff --git a/lib/data/game.js b/lib/data/game.js index ee4ae02..0a66138 100644 --- a/lib/data/game.js +++ b/lib/data/game.js @@ -4,5 +4,7 @@ GridGame.data.game = { turn_time: 100, spawn_interval: 3, city_conversion_size: 10, - rock_count: 0, + rock_count: 10, + wall_count: 100, + wall_health: 100 }; diff --git a/lib/grid_game.js b/lib/grid_game.js index b070dc1..f37efa4 100644 --- a/lib/grid_game.js +++ b/lib/grid_game.js @@ -14,7 +14,10 @@ var GridGame = { this.turn_time = GridGame.data.game.turn_time; this.spawn_interval = GridGame.data.game.spawn_interval; this.city_conversion_size = GridGame.data.game.city_conversion_size; + this.rock_count = GridGame.data.game.rock_count; + this.wall_count = GridGame.data.game.wall_count; + this.wall_health = GridGame.data.game.wall_health; this.game_space = $('#grid_game'); this.turn_number = 0; @@ -66,9 +69,8 @@ var GridGame = { }, init_obstacles: function() { - for(var i = this.rock_count; i > 0; i--){ - this.board.place_random_rock(); - } + this.board.place_n_obstacles('rock', this.rock_count); + this.board.place_n_obstacles('wall', this.wall_count); }, // Operation diff --git a/lib/turn_phases/do_damage_phase.js b/lib/turn_phases/do_damage_phase.js index dde89e2..ce7d290 100644 --- a/lib/turn_phases/do_damage_phase.js +++ b/lib/turn_phases/do_damage_phase.js @@ -10,6 +10,7 @@ GridGame.turn_phases.do_damage_phase = function() { this.player = null; this.value = 0; this.city = false; + this.wall = false; }; }; diff --git a/lib/turn_phases/do_movement_phase.js b/lib/turn_phases/do_movement_phase.js index 6e28aca..33eea50 100644 --- a/lib/turn_phases/do_movement_phase.js +++ b/lib/turn_phases/do_movement_phase.js @@ -7,7 +7,7 @@ GridGame.turn_phases.do_movement_phase = function () { }; this.do_city_conversion = function() { - if (!this.city && this.value >= GridGame.city_conversion_size) { + if (!this.city && this.value >= GridGame.city_conversion_size && this.player != null) { this.value = 10; this.city = true; } diff --git a/lib/turn_phases/mark_damage_phase.js b/lib/turn_phases/mark_damage_phase.js index 9d894e1..b1ff795 100644 --- a/lib/turn_phases/mark_damage_phase.js +++ b/lib/turn_phases/mark_damage_phase.js @@ -1,7 +1,7 @@ GridGame.turn_phases.mark_damage_phase = function() { this.mark_damage_phase = function() { - if (this.player) { + if (this.player || this.wall) { var tile = this; $.each( this.neighbours(), @@ -15,12 +15,12 @@ GridGame.turn_phases.mark_damage_phase = function() { this.mark_damage_from_neighbour = function (neighbour) { if (!neighbour) {return false} if (!neighbour.player) {return false} - var neighbour_belongs_to_enemy = (neighbour.player != this.player); - + var neighbour_belongs_to_enemy = (this.player == null || neighbour.player != this.player); var neighbour_is_alive = neighbour.value > 0; + if (neighbour_belongs_to_enemy && neighbour_is_alive) { this.value_change -= neighbour.value; } - } + }; }; diff --git a/style/grid_game.css b/style/grid_game.css index b99a252..ca3da17 100644 --- a/style/grid_game.css +++ b/style/grid_game.css @@ -113,13 +113,17 @@ table.game_board tr.row td.tile_yellow { color: orangered; } -table.game_board tr.row td.tile_city small { +table.game_board tr.row td.tile small { font-size:10px; } table.game_board tr.row td.tile_rock { background-color: #777777; - color: #444444; +} + +table.game_board tr.row td.tile_wall { + background-color: #ff190E; + color: #dddddd; } .footer {