Skip to content

Commit

Permalink
Finally completely even games
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew james faraday committed Oct 17, 2019
1 parent c07394a commit 0e80200
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 10 deletions.
4 changes: 3 additions & 1 deletion lib/grid_game.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ var GridGame = {
},

turn_active: false,
callbacks: [],

turn: function () {
$.each(GridGame.apis, function (i, api) {
Expand All @@ -142,10 +143,11 @@ var GridGame = {

GridGame.check_players_alive();
GridGame.turn_number += 1;
$('span#turn').html(GridGame.turn_number);
if (GridGame.tournament) {
$('span#turn').html(GridGame.turn_number);
GridGame.info.get_all();
}
$.each(GridGame.callbacks, function(i, c) {c()})
},

spawning_turn: function () {
Expand Down
26 changes: 18 additions & 8 deletions lib/turn_phases/mark_movement_phase.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,30 @@ GridGame.turn_phases.mark_movement_phase = function() {
this.fight_with = function(target){
console.log('little fight at turn ' + GridGame.turn_number);

if (this.value_cahnge > 0) {
console.log(this.value_change);
}
var target_value = (target.value + target.value_change);
var this_value = (this.value + this.value_change);

var win = (this.value) > target_value;
var draw = this.value == target_value;
var lose = this.value < target_value;
var win = (this_value) > target_value;
var draw = this_value == target_value;
var lose = this_value < target_value;
if (win) {
console.log(this.player.name + ' wins');
this.value_change -= this.value;
this.value_change -= this_value;
target.value_change -= target_value;
target.value_change += (this.value - target_value);
target.value_change += (this_value - target_value);
target.player = this.player;
target.changed_player = true;
} else if (draw) {
console.log('drawn');
this.value_change -= this.value;
this.value_change -= this_value;
target.value_change -= target_value;
} else if (lose) {
console.log(target.player.name + ' wins');
target.value_change -= this.value;
target.value_change -= this_value;
this.value_change -= this_value;
}
};

Expand All @@ -57,7 +62,12 @@ GridGame.turn_phases.mark_movement_phase = function() {

this.spawn_unit = function() {
var move_target = this.move_target();
if(this.player.can_step_onto(move_target)) {
if (this.enemy_walker_at(move_target)) {
console.log('spawning on top of enemy')
move_target.value_change -= 1;
// TODO handle situation where walkers spawn on top of enemy walkers
// this.fight_with(move_target);
} else if(this.player.can_step_onto(move_target)) {
this.player.mark_step_onto(move_target, 1);
}
};
Expand Down
15 changes: 14 additions & 1 deletion tournament.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<script type="text/javascript" src="./lib/api_ui.js"></script>

<link rel="stylesheet" href="./style/grid_game.css"/>
<script src="lib/info.js"></script>
</head>
<body>
<h1>Grid Game</h1>
Expand Down Expand Up @@ -134,7 +135,7 @@ <h1>Grid Game</h1>
GridGame.init(
{
tournament: true,
turn_time: 50,
turn_time: 5,
width: 23, // works at 19, almost at 23
height: 12
}
Expand All @@ -149,6 +150,18 @@ <h1>Grid Game</h1>
if(green_gist) {
set_player_to_gist('green', green_gist)
}

// tODO remove when you've worked this out
GridGame.callbacks.push(
function() {
// TODO remove (won't make a great game)
var hash = GridGame.info.get_overall_health();
if (hash.red != hash.green) {
GridGame.stop();
}
//TODO add periodic pausing for tournaments
}
);
});
</script>
</body>
Expand Down

0 comments on commit 0e80200

Please sign in to comment.