-
-
Save slior/2284ff2f41360ca559603ee2f01f4349 to your computer and use it in GitHub Desktop.
Mancala (4247ec9a7e36bb31710aa52fb1349ed710ac154c) - adding game over
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MancalaGame | |
{ | |
constructor(cnvsELID,_updatePlayerCallback,_showMsgCallback) | |
{ | |
... | |
this.gameDone = false; | |
... | |
} | |
handleCellClick(boardCell) | |
{ //todo: clean this up | |
if (this.gameDone) | |
{ | |
dbg("Game over, get outta here"); | |
return; | |
} | |
... | |
let currentPlayerHasNoMoreMoves = this.player1Playing(this.board.allPlayer1Cells(c => this.board.stonesIn(c) <= 0)) || | |
this.player2Playing(this.board.allPlayer2Cells(c => this.board.stonesIn(c) <= 0)) | |
if (currentPlayerHasNoMoreMoves) | |
this.gameOver(); | |
this.canvas.ifPresent(cnvs => { | |
drawBoardState(cnvs,this.board,this) | |
}) | |
} | |
} | |
gameOver() | |
{ | |
let player1StoneCount = this.board.player1StoneCount(); | |
let player2StoneCount = this.board.player2StoneCount(); | |
let a = ["Game Over","# Stones P1:" + player1StoneCount,"# Stones P2: " + player2StoneCount]; | |
switch (true) | |
{ | |
case player1StoneCount > player2StoneCount : a.push("Player 1 Wins!"); break; | |
case player2StoneCount > player1StoneCount : a.push("Player 2 Wins!"); break; | |
default : a.push("Draw!"); break; | |
} | |
this.showMsg(a.join("<br/>")); | |
this.setGameOver(); | |
} | |
setGameOver() { this.gameDone = true; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment