Knochenmark / minesweeper

Minesweeper Game
https://knochenmark.github.io/minesweeper/
3 stars 1 forks source link

First click can trigger bomb #108

Open wtho opened 5 years ago

wtho commented 5 years ago

Describe the bug When starting a new game, sometimes (especially on hard) the first click will already trigger a bomb. The fix of this would be a time-saver for power player.

To Reproduce

  1. New Game
  2. Click on random tile
  3. Bomb explodes! If not, proceed with step 1

Expected behavior In the "original" windows minesweeper the first click could never trigger a bomb. I guess the map was either generated on this first click, or several maps were generated and the first one without a bomb on the clicked tile was then used.

Knochenmark commented 5 years ago

Thanks for reporting. Are you sure about that first click never triggered a bomb? I think I remember they would still trigger nontheless.

I also don't think that this is too much of an issue, since you can just restart the game immeadiately by pressing the R hotkey. Technically you could just hover a cell and click it, see if it is a mine and press R and try again. I've added this originally for testing purposes but it was too convenient to be removed again.

Greetings fellow Berliner ;)

wtho commented 5 years ago

Yeah I am quite sure you could not click on bombs.

I tried to delay the map generation until the first click happens in here https://github.com/Knochenmark/minesweeper/blob/61d4aed95201a817aba04ef50c0935ae5a730a6c/src/mine-sweeper.tsx#L245-L250

adding something like

this.setState({ 
  mineField: generateMineField(rows, columns, mines, clickX, clickY),
  gameStatus: GameStatus.RUNNING,
}); 

and previously only generating an empty fake mine field, but somehow react sticks to the empty one and does not recognize the new mineField in setState. :confused: