Minesweeper C++

1.5k Views Asked by At

I've written the minesweeper game for C++, and the core game is complete.

There are three things I need to ask.

  1. Currently, my mines are placed at random positions.. I was wondering if this is true for the actual game? Are the mines random or is their some specific pattern or algorithm for placing the mines.

  2. When I play minesweeper on Win 7, I never see a 0. But in my program, there are cases when all 8 neighbors are non mines. What should I display then? I want the game to be as close to the Windows version as possible.

  3. I think this may be related to 2 above, when I play on Win 7 sometimes when I click on a cell multiple cells are revealed. I want to do this in my program but I don't know the controlling logic behind it. I mean, when does this have to happen? And when it does happen, how do I know how many and which cells to open up?

On a related note, my current program is text based (in code blocks). Currently I know only C++. What do I need to learn to be able to make the game interactive?

2

There are 2 best solutions below

0
On BEST ANSWER
  1. Yes they are placed at random. You need to make sure that you don't place two mines in the same spot.

  2. A 0 is displayed as a blank in windows.

  3. When you expose a square with no adjacent mines, it will automatically expose all 8 of those squares. If any of those are also zeros, they will be exposed also until an entire region is exposed.

0
On
  1. The first guess is never a mine, so your generation algorithm must delay itself until this happens. As far as I am aware, mines are placed pseudo randomly.

  2. When no adjacent mines are found on a guessed square, it reveals all adjacent squares.

  3. On the versions I have played, when you left click and then right click together and when a location has a sufficient number of flags placed around it, it reveals all adjacent squares.