JavaScript, HTML, CSS. Names are editable. The game is not really optimized for a small screen. Inspired by Jonas Schmedtmann, copyright by Jonas Schmedtmann, implementation is mine.
Since we know that the game begins with the player player--0
, a smarter way to switch currect player is:
let activePlayer = 0;
If dice is not qual to 1:
document.getElementById(`current--${activePlayer}`).textContent
If dice is equal to 1:
activePlayer = activePlayer === 0 ? 1 : 0;
Instead of using .classList.add('player--active')
or .classList.remove('player--active')
:
'player1'.classList.toggle('player--active');
'player2'.classList.toggle('player--active');
Winner is the one who gets 100 point first. If the dice is ONE then you loose you current points. You can click HOLD to add your current points to your total, but you loose your turn.