private void openTile(int x, int y) {
GameObject cell = gameField[y][x];
if (cell.isOpen == true)
{
return;
}
cell.isOpen = true;
setCellColor(x, y, Color.GREEN);
if (cell.isMine)
{
setCellValue(x, y, MINE);
setCellColor(x, y, Color.RED);
} else if (cell.countMineNeighbors == 0) {
setCellValue(x, y, "");
List < GameObject > neighbors = getNeighbors(cell);
for (GameObject g:neighbors) {
if (g.isOpen == false && g.isMine == false && g.countMineNeighbors == 0)
openTile(g.x, g.y);
}
} else {
setCellNumber(x, y, cell.countMineNeighbors);
}
}
lizhi
Level 20
Why is my recursion useless? Help!!
Resolved
Comments (9)
- Popular
- New
- Old
You must be signed in to leave a comment
Guadalupe Gagnon
19 March 2021, 13:13
what task are you on?????????
These big tasks will have you update methods in subsequent tasks as you go along. There is no way for us to just help you correctly without knowing what the task conditions are. My openTile() method is way different then yours. It checks if the game is stopped, if the tile is a flag, if the tile is a mine, if the tile is already open. It also increases the score, checks for the win condition, and ends the game if it is a mine.
0
Guadalupe Gagnon
19 March 2021, 13:20
This entire line should probably be removed:
the first if check in the method already checks if the cell is open:
there won't be any mines if it reaches this line as this is in the if block
which wouldn't be true if there were any mines, and all the neighbors should be open, not just the ones that are 0. 0
lizhi
20 March 2021, 00:52
l am on ninth task
0
lizhi
20 March 2021, 01:04
Here's what i think.
The first thing is check if it's clicked and if it's clicked then i'm going to return ;
and then i determine if it's ray .
if it's a ray ,then setCellValue(),
if it isn't and it hasn't MineNeighbor ,i'll find all his neighbor ,
if (g.isOpen == false && g.isMine == false && g.countMineNeighbors == 0) (avoid doing thing on the same cell )and then call openTile(g.x,g.y)
it he's not ray,then the number of neighbors is not zero ,then call setCellNumber
0
lizhi
20 March 2021, 01:07
Because i 'm Chinese ,so my English may be hard for you to understand .Sorry!😅
0
Guadalupe Gagnon
20 March 2021, 15:46
Just remove that line. It is preventing the task from passing.
0
lizhi
20 March 2021, 23:05
The First task requirements is not met.
The First Requirement : In the openTile(int, int) method, if the element is not a mine and has no mined neighbors, the openTile(int, int) method must be called recursively on each neighbor that hasn't been revealed.
I can't understand why I'm wrong.
0
lizhi
20 March 2021, 23:05
After i remove that line
0
Guadalupe Gagnon
21 March 2021, 17:28
You should really attach your solution when asking for help. The problem may not even be in that method but one of the other methods this one uses. Without seeing all the code plus what points are failing it makes it almost impossible to help.
0