2022-01-03
This simple Dice game allows two playes to keep rolling the dice until a player gets a total of 20 points and is declared the winner.
#CodeSteps
- Create variables for the game state
- Create variables to store references to the necessary DOM nodes
- Hook up a click event listener to the Roll Dice Button. Log out a random number between 1 and 6.
Hint: use Math.floor() and Math.random()
- Find out which players turn it is
- log out the value e.g. "Player 1 rolled 5"
- Switch the turn back to the other player
- Display the dice number instead of logging it out
- Use the 'active' class to show which player's turn it is
Hint: use the .classList.remove() and classlist.add() methods*
- Update the "message" DOM node so that it states who's turn it is
- Update the scores for each player
- Display the scores in their scoreboards
- Check if a player has won. If so, change the message to "Player X has won!"
- Hide the Roll Dice Button and show the Reset Button. Hint: use display none/block
- Hook a click event listener up with the Reset Button
- Create a reset() function that resets the game
- Invoke the reset() function when the Reset Button is clicked
For more check :
- HTML
- CSS
- JavaScript
IDE
- Change dice rolled to show image of dice not number
- Make the game fair "each player must have equal roll, and the closer to 20 wins"