From a4130986757165fcf72056d97a1608c41bd6abb4 Mon Sep 17 00:00:00 2001 From: Justin Worthe Date: Wed, 14 May 2014 14:30:24 +0200 Subject: Added condition for game ending re #9 --- game/states/play.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/game/states/play.js b/game/states/play.js index e05a65f..49c6cca 100644 --- a/game/states/play.js +++ b/game/states/play.js @@ -46,6 +46,20 @@ Play.prototype = { }, update: function() { this.game.physics.arcade.overlap(this.players, this.pills, this.playerPillCollision, null, this); + + if (this.pills.total === 0) { + + if (this.playerA.score > this.playerB.score) { + console.log("PLAYER A WINS!"); + } + else if (this.playerA.score < this.playerB.score) { + console.log("PLAYER B WINS!"); + } + else { + console.log("THIS GAME WAS A DRAW!") + } + this.game.state.start('play'); + } }, createWalls: function() { this.walls = this.game.add.group(); -- cgit v1.2.3