Skip to content

Commit

Permalink
Feature #11: Walls appear, have health, lose health, disappear
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Faraday committed Oct 12, 2016
1 parent 510c220 commit 9b27fd3
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 20 deletions.
16 changes: 12 additions & 4 deletions lib/classes/board.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
}
};

Expand Down
8 changes: 5 additions & 3 deletions lib/classes/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
)
};

Expand Down
8 changes: 6 additions & 2 deletions lib/classes/tile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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<small>' + this.value + '</small>';
} else if (this.wall) {
return '<small>' + this.value + '</small>';
} else {
return this.value;
}
Expand Down
4 changes: 3 additions & 1 deletion lib/data/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
8 changes: 5 additions & 3 deletions lib/grid_game.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/turn_phases/do_damage_phase.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ GridGame.turn_phases.do_damage_phase = function() {
this.player = null;
this.value = 0;
this.city = false;
this.wall = false;
};

};
2 changes: 1 addition & 1 deletion lib/turn_phases/do_movement_phase.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
8 changes: 4 additions & 4 deletions lib/turn_phases/mark_damage_phase.js
Original file line number Diff line number Diff line change
@@ -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(),
Expand All @@ -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;
}
}
};

};
8 changes: 6 additions & 2 deletions style/grid_game.css
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 9b27fd3

Please sign in to comment.