Skip to content

Commit

Permalink
Implement basic game over
Browse files Browse the repository at this point in the history
  • Loading branch information
mhawryluk committed Nov 9, 2023
1 parent 67f8df9 commit ef169e7
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions game.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,13 @@ class Game {
if (oldTile) this.distributeTokensOnOneTile(oldTile);
this.distributeTokensOnOneTile(newTile);

if (this.lastRolledValue !== 6) {
this.resetRolledValue();
this.clearPossibleMoves();

if (!this.checkForGameOver(player) && this.lastRolledValue !== 6) {
this.nextPlayer();
}

this.resetRolledValue();
this.clearPossibleMoves();
return true;
}

Expand Down Expand Up @@ -170,13 +171,26 @@ class Game {
allTokensOnTile[i].setAttribute('translation', `${tile[1] + yOffset} 1 ${tile[0] + xOffset}`);
}
}

checkForGameOver(player) {
for (let i = 0; i < 4; i++) {
if (this.tokenPositons[player][i] !== playerPaths[player].length - 1) {
return false;
}
}

popup.innerHTML = `<div>${player} won!</div>`;
popup.style.display = 'flex';
side.style.opacity = 0;
return true;
}
}

rollDiceButton.addEventListener('click', () => {
if (game.lastRolledValue == 0) {
game.rollDice();
} else {
alert('already rolled, make a move!');
alert('Aready rolled, make a move!');
}
});

Expand Down

0 comments on commit ef169e7

Please sign in to comment.