From 0e8020004e1588dc3b5285d27ef36867ea7f0dc7 Mon Sep 17 00:00:00 2001 From: andrew james faraday Date: Thu, 17 Oct 2019 13:20:44 +0100 Subject: [PATCH] Finally completely even games --- lib/grid_game.js | 4 +++- lib/turn_phases/mark_movement_phase.js | 26 ++++++++++++++++++-------- tournament.html | 15 ++++++++++++++- 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/lib/grid_game.js b/lib/grid_game.js index 67c6cb1..2eb4e23 100644 --- a/lib/grid_game.js +++ b/lib/grid_game.js @@ -119,6 +119,7 @@ var GridGame = { }, turn_active: false, + callbacks: [], turn: function () { $.each(GridGame.apis, function (i, api) { @@ -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 () { diff --git a/lib/turn_phases/mark_movement_phase.js b/lib/turn_phases/mark_movement_phase.js index 3f288d8..7743b18 100644 --- a/lib/turn_phases/mark_movement_phase.js +++ b/lib/turn_phases/mark_movement_phase.js @@ -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; } }; @@ -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); } }; diff --git a/tournament.html b/tournament.html index 7363bb2..d3f8936 100644 --- a/tournament.html +++ b/tournament.html @@ -54,6 +54,7 @@ +

Grid Game

@@ -134,7 +135,7 @@

Grid Game

GridGame.init( { tournament: true, - turn_time: 50, + turn_time: 5, width: 23, // works at 19, almost at 23 height: 12 } @@ -149,6 +150,18 @@

Grid Game

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 + } + ); });