-
-
Save slior/727dbfe59b8afcee1b796bc2f97fc8f8 to your computer and use it in GitHub Desktop.
Mancala (db555b58544181ff4c4c34b3d951f8f77e91c833) - adding ability to change game size
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(gameSize,cnvsELID,_updatePlayerCallback,_showMsgCallback) | |
{ | |
... | |
this.cellCount = gameSize; | |
... | |
this.board = new Board(this.cellCount); | |
} | |
_initializeBoardDrawing() | |
{ | |
... | |
drawBoard(cnvs,this.cellCount); | |
... | |
} | |
} |
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
<script> | |
const SIZE_PARAM_NAME = 'size'; | |
const DEFAULT_GAME_SIZE = 14; | |
const GAME_SIZE_UPPER_BOUND = 28; | |
const GAME_SIZE_LOWER_BOUND = 6; | |
... | |
function setup() | |
{ | |
game = new main.MancalaGame(resolveGameSize(),'cnvsMain',updateCurrentPlayer,showMsg); | |
} | |
function resolveGameSize() | |
{ | |
let params = new URLSearchParams(window.location.search); | |
let size = (params.has(SIZE_PARAM_NAME) && !isNaN(params.get(SIZE_PARAM_NAME))) ? | |
params.get(SIZE_PARAM_NAME)*1 : DEFAULT_GAME_SIZE; | |
let ret = Math.max( //we bound the game size between the minimum and the upper bound | |
Math.min(size | |
,GAME_SIZE_UPPER_BOUND || DEFAULT_GAME_SIZE) | |
,GAME_SIZE_LOWER_BOUND); | |
if (ret % 2 != 0) ret -= 1; //we have to make sure it's a divisble by 2. | |
console.log("Game size: " + ret); | |
return ret; | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment