V
V
Valery Kovalev2019-04-07 01:50:52
Java
Valery Kovalev, 2019-04-07 01:50:52

How to open cells where there are no bombs for the Minesweeper game?

I'm writing a sapper game in JavaFX, I can't figure it out.
There is a field of squares. Any square can be accessed through the grid along the x and y axes:
grid.get(0, 3);
grid.get(0, Y_TILES);
Each square has an int variable, this is the number of bombs around;
grid.get(0,0).bombsAround.
When clicking on a square that has bombsAround==0, I want all neighboring squares that also have 0 to open. The game is already working, but you just have to poke many times where there are no bombs.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel, 2019-04-07
@youkerni

recursion to help you.
for each adjacent cell without bombs nearby, open all neighboring cells without bombs nearby.
there may be an overhead from the fact that some cells will be "opened" several times, so I would introduce a boolean flag isOpened

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question