Skip to content

Instantly share code, notes, and snippets.

@slior

slior/game.js Secret

Created November 3, 2020 10:23
Show Gist options
  • Save slior/314009370524969ad59920945dabb990 to your computer and use it in GitHub Desktop.
Save slior/314009370524969ad59920945dabb990 to your computer and use it in GitHub Desktop.
Mancala (6835c79502cd2e0ff49b102769e0fe5776306ec0) - introducing MancalaGame and players
...
class MancalaGame
{
constructor(cnvsELID,_updatePlayerCallback)
{
requires(_updatePlayerCallback != null,"Must have a player update callback")
this.board = new Board(CELL_COUNT);
this.player = PLAYER.one;
this.updatePlayerCallback = _updatePlayerCallback;
this.updatePlayerCallback(this.player);
this.canvas = maybe(initCanvas(cnvsELID));
this.canvas.ifPresent(cnvs => {
...
})
}
handleCellClick(boardCell)
{
this.board.playCell(boardCell);
this.updatePlayerCallback(this.togglePlayer());
this.canvas.ifPresent(cnvs => {
drawBoardState(cnvs,this.board,this)
})
}
togglePlayer()
{
this.player = this.player.theOtherOne();
return this.player;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment