lahacheck.blogg.se

How to make a simple minesweeper game in javascript
How to make a simple minesweeper game in javascript





how to make a simple minesweeper game in javascript

If the number of flags surrounding equals the number in this square, we open up the unflagged squares using the same procedure as above. Multiguess: The player clicks on a square that is uncovered and known to be safe. This should be in a dedicated function, to separate it from the GUI's event handler, to make the recursion easy, and because it's reused in the multiguess. If the square contains a 0, repeat this recursively for all the surrounding squares. Reveal the square, see if the player died, and put a number in it. Single guess: The player clicks on a square with unknown state and no flag. Playing the gameīesides marking flags, the player can make two kinds of moves to attempt to uncover squares: I have never seen this in action, but it would be kind of fun.

how to make a simple minesweeper game in javascript

This takes some cleverness, and isn't done in most variants.Īnother, less common way to resolve ambiguities is to detect when the player knows they are choosing between equally likely possibilities and "collapse the waveform" into the position they decided on. Improvement: Run the solver alongside the generator, making sure that the puzzle has a unique solution. Problem: The player might be forced to guess at some point, making this a sad excuse for a logic puzzle. Improvement: Don't generate any mines in the (up to) eight squares around the first click, either. Problem: The player's first click might reveal a non-zero number, and they will be forced to click randomly until something opens up. Improvement: Delay the generation of the grid until the user clicks on the first square, and don't put any mines in that square. Problem: The player's first click might be a mine. The simplest algorithm is to place all of the mines randomly. There are a couple simple algorithms that you need when executing the player's move, to determine which squares to open up and whether they have lost or won.







How to make a simple minesweeper game in javascript