We're going to build a classic: Minesweeper 😀
The game works like this:
- There is a field of 100 tiles with hidden contents. There are mines randomly placed.
- When you hit a mine, the game ends
- When you click a tile and there is no mine underneath, it is cleared.
- Any adjecent tiles that do not have mines around will also be cleared.
- When all tiles are cleared, you've won the game.
You can try the game here: https://minesweeper.online/start/1
You can use the existing code but feel free to rewrite anything.
- In the top right corner, fork this repo.
- Handle a click on a mine (game ends)
- Handle a click on a tile without a mine: set
showContent
totrue
of the current tile - Then also reveal any adjecent tiles that have no mines around.
- Then also reveal any adjecent tiles that have some 1 or more mines around.
- Done? Help a fellow colleague with some tips!
- Continue: In
generateGame
, replace that static grid. Dynamically generate it with random mine placement - Bonus: Handle a right click (show a flag)
- Bonus: Find a fun challange to share on codewars.com