You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: minesweeper-game/README.md
+8-2
Original file line number
Diff line number
Diff line change
@@ -14,14 +14,20 @@
14
14
15
15
1. Create a constant grid Container using querySelector(".grid"), and a const GAME_WIDTH to specify the game size while creating the game board.
16
16
2. Use document.addEventListener("DOMContentLoaded"()=>{ } ) for the rest of the game functionality.
17
-
3. Create the board by adding 100 boxes to it, using createElement(), setAttribute() & AppendChild() in the for loop.
17
+
3. Create the board using createBoard() method, by adding 100 boxes to it, using createElement(), setAttribute() & AppendChild() in the for loop.
18
18
4. Create a ShuffledArray that includes bomb & other elements at random position, and add it to each box in the for loop using box.classList.add().
19
19
5. In method addNumbersToBoard(), specify conditions to add number of neighbouring bombs to the each valid (non-bomb) box.
20
20
7. Use setAttribute() to add the "total" attribute and it's value to each valid box element.
21
-
8. Add eventListener for click event, and add a new class "checked" on click of a valid box.
21
+
8. Add eventListener for click event in createBoard(), and call a new method click(). Then add a new class "checked" on click of a valid box.
22
22
9. Assign value of "total" to the valid box using getAttribute(), and then call a new method checkBox() for recursive steps.
23
23
10. Create a new file recurse.js and export the checkBox() method.
24
+
11. Implement recursion in the checkBox() method, to display total value of neighbouring boxes of the clicked box. The recursion continues until and edge or a bomb is the neighbouring element.
25
+
12. Create a gameOver() method, the assigns true to isGameOver variable, and displays all the bombs once a bomb is clicked by the player.
26
+
13. Create addFlag() method, to add flags on the boxes that have bomb element and are right clicked by the player, to mark as safe.
27
+
14. Use onContextMenu property in createBoard(), that calls addFlag() on right click on a box with bomb element.
28
+
15. Create a gameWin() method to check if the number of flags added by the player matches the total number of bombs. If yes, then the player is declared as Winner. This method is called everytime a flag is added to the game board.
24
29
25
30
## Resources
26
31
27
32
1.[MineSweeper using JS](https://www.youtube.com/watch?v=W0No1JDc6vE&t)
0 commit comments