Skip to content

Commit

Permalink
Merge pull request #7 from AJFaraday/feature_2_obstacles
Browse files Browse the repository at this point in the history
Feature 2 obstacles
  • Loading branch information
AJFaraday authored Oct 11, 2016
2 parents 644a639 + 457eb09 commit 8bc10fa
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 17 deletions.
13 changes: 12 additions & 1 deletion lib/classes/board.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ GridGame.classes.board = function () {
var row = [];
for (var x = 0; x < GridGame.width; x++) {
var tile = this.build_tile(x, y);
row.push(tile)
row.push(tile);
current_row.append(tile.build());
}
this.rows.push(row);
Expand Down Expand Up @@ -83,5 +83,16 @@ GridGame.classes.board = function () {

};

this.place_random_rock = function() {
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();
} else {
tile.rock = true;
}
};

};

4 changes: 3 additions & 1 deletion lib/classes/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ GridGame.classes.player = function (config) {
var target_belongs_to_me = (target.player == this);
var target_is_city = target.city;
var target_already_stepped_to = target.changed_player;
var target_is_rock = target.rock;
return (
target_present &&
(target_unowned || target_belongs_to_me) &&
!target_is_city &&
!target_already_stepped_to
!target_already_stepped_to &&
!target_is_rock
)
};

Expand Down
27 changes: 15 additions & 12 deletions lib/classes/tile.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ GridGame.classes.tile = function (x, y) {
this.player = null;
this.value = 0;
this.city = false;
this.rock = false;

// used in turn process
this.value_change = 0;

GridGame.turn_phases.mark_movement_phase.apply(this);
GridGame.turn_phases.do_movement_phase.apply(this);
GridGame.turn_phases.mark_damage_phase.apply(this);
Expand All @@ -32,7 +33,7 @@ GridGame.classes.tile = function (x, y) {
this.neighbour_north_west(),
this.neighbour_north(),
this.neighbour_north_east(),
this.neighbour_west(),
this.neighbour_west(),
this.neighbour_east(),
this.neighbour_south_west(),
this.neighbour_south(),
Expand All @@ -48,15 +49,15 @@ GridGame.classes.tile = function (x, y) {
return GridGame.board.tile(x, y - 1);
};

this.neighbour_north_east = function() {
this.neighbour_north_east = function () {
return GridGame.board.tile(x + 1, y - 1);
};

this.neighbour_west = function() {
this.neighbour_west = function () {
return GridGame.board.tile(x - 1, y);
};

this.neighbour_east = function() {
this.neighbour_east = function () {
return GridGame.board.tile(x + 1, y);
};

Expand All @@ -68,10 +69,10 @@ GridGame.classes.tile = function (x, y) {
return GridGame.board.tile(x, y + 1);
};

this.neighbour_south_east = function() {
this.neighbour_south_east = function () {
return GridGame.board.tile(x + 1, y + 1);
};

this.build = function () {
this.cell.addClass('tile');

Expand All @@ -82,11 +83,13 @@ GridGame.classes.tile = function (x, y) {

this.draw = function () {
this.cell
.html(this.display_character())
.removeClass(function(index, css) {
return (css.match (/\btile_\S+/g) || []).join(' ');
})
.toggleClass('tile_city', this.city);
.html(this.display_character())
.removeClass(function (index, css) {
return (css.match(/\btile_\S+/g) || []).join(' ');
})
.toggleClass('tile_city', this.city)
.toggleClass('tile_rock', this.rock);


if (this.player && this.value > 0) {
this.cell.addClass('tile_' + this.player.name);
Expand Down
5 changes: 3 additions & 2 deletions lib/data/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ GridGame.data.game = {
height: 12,
turn_time: 100,
spawn_interval: 3,
city_conversion_size: 10
};
city_conversion_size: 10,
rock_count: 5,
};
9 changes: 8 additions & 1 deletion lib/grid_game.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ 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.game_space = $('#grid_game');
this.turn_number = 0;

this.init_dom();
this.init_board();
this.init_players();
this.init_obstacles();
this.init_keyboard();
GridGame.board.draw();

Expand Down Expand Up @@ -62,6 +63,12 @@ var GridGame = {
this.keyboard = new GridGame.classes.keyboard();
this.keyboard.init();
},

init_obstacles: function() {
for(var i = this.rock_count; i > 0; i--){
this.board.place_random_rock();
}
},

// Operation

Expand Down
4 changes: 4 additions & 0 deletions style/grid_game.css
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ table.game_board tr.row td.tile_city small {
font-size:10px;
}

table.game_board tr.row td.tile_rock {
background-color: #777777;
color: #444444;
}

.footer {
float:left;
Expand Down

0 comments on commit 8bc10fa

Please sign in to comment.