A simple React-based dice game where the goal is to roll all dice to show the same number. This project was built as a learning exercise to practice React fundamentals and improve accessibility and UI behavior. Capstone Project of the Learn React Course on Scrimba.com
The game is deployed and hosted on Netlify. You can check out the live demo here: Tenzies Game Live Demo
- Roll 10 dice and hold specific ones to keep their values.
- Detects when all dice are held and show the same value to declare a win.
- Allows restarting the game after winning.
useState: Used to manage dice values and held status.- Props and Component Design: Created a reusable component that receives value, hold status, and click behavior as props.
useRef: Used to access the underlying DOM node of the roll button so it can be focused when the player wins the game.useEffect: Used to synchronize the application state with an external system (the DOM) by calling.focus()on the button when gameWon becomes true. This ensures accessibility and a better user experience.
- Dice update only if they’re not held.
- UI updates depending on whether the player has won or not.
- Each die is given a unique ID using the
nanoidpackage to ensure stable list rendering.
- Used the
react-confettipackage to show a simple celebration effect when the game is won.
- ARIA attributes: Added
aria-labelandaria-pressedto dice buttons for screen reader support. - Live Region: Used
aria-live="polite"to notify screen reader users about game status changes. - Focus Management: Used
useRefanduseEffectto shift focus to the "New Game" button when the game is won.
- Click "Roll" to randomize dice.
- Click individual dice to hold their values.
- Try to get all dice to show the same number.
- When you win, click "New Game" to start again.
