# Help calling a method recursively

**807600**Nov 19, 2007 12:05 PM

i'm writing a little text-based minesweeper game and need some help. when you hit a blank space, all the spaces around it and the numbers bordering them are supposed to be revealed, just like in the real game:

http://img252.imageshack.us/img252/7953/minesweeperwk3.jpg

this method is called when a user enters a coordinate (1-9) of the 10x10 array.

first, it's supposed to check if the cell they picked is not a mine (which is labeled as F for flag). there is a display array that shows what is currently on the screen and a solution array which holds the solution.

next it is supposed to check the surrounding 8 squares, starting at the one above it and going clockwise. if a square is empty, then it should call the method again and start at that square, and once it's done, go back to the original square, therefore going through all the possible squares. also, the if statements check if a surrounding cell is not out of bounds. i just can't seem to figure it out though. any help is appreciated.

http://img252.imageshack.us/img252/7953/minesweeperwk3.jpg

this method is called when a user enters a coordinate (1-9) of the 10x10 array.

first, it's supposed to check if the cell they picked is not a mine (which is labeled as F for flag). there is a display array that shows what is currently on the screen and a solution array which holds the solution.

next it is supposed to check the surrounding 8 squares, starting at the one above it and going clockwise. if a square is empty, then it should call the method again and start at that square, and once it's done, go back to the original square, therefore going through all the possible squares. also, the if statements check if a surrounding cell is not out of bounds. i just can't seem to figure it out though. any help is appreciated.

```
public static boolean setSquareVisible(int row, int col) {
if(solution[row][col] != 'F') {
if (solution[row][col] == ' ') {
if ((row - 1) >= 0) {
if (solution[row - 1][col] != 'F') {
display[row - 1][col] = solution[row - 1][col];
setSquareVisible(row - 1, col);
}
}
if ((row - 1) >= 0 && (col + 1) < 10) {
if (solution[row - 1][col + 1] != 'F') {
display[row - 1][col + 1] = solution[row - 1][col + 1];
setSquareVisible(row - 1, col + 1);
}
}
if ((col + 1) < 10) {
if (solution[row][col + 1] != 'F') {
display[row][col + 1] = solution[row][col + 1];
setSquareVisible(row, col + 1);
}
}
if ((row + 1) < 10 && (col + 1) < 10) {
if (solution[row + 1][col + 1] != 'F') {
display[row + 1][col + 1] = solution[row + 1][col + 1];
setSquareVisible(row + 1, col + 1);
}
}
if ((row + 1) < 10) {
if (solution[row + 1][col] != 'F') {
display[row + 1][col] = solution[row + 1][col];
setSquareVisible(row + 1, col);
}
}
if ((row + 1) < 10 && (col - 1) >= 0) {
if (solution[row + 1][col - 1] != 'F') {
display[row + 1][col - 1] = solution[row + 1][col - 1];
setSquareVisible(row + 1, col - 1);
}
}
if ((col - 1) >= 0) {
if (solution[row][col - 1] != 'F') {
display[row][col - 1] = solution[row][col - 1];
setSquareVisible(row, col - 1);
}
}
if ((row - 1) >= 0 && (col - 1) >= 0) {
if (solution[row - 1][col - 1] != 'F') {
display[row - 1][col - 1] = solution[row - 1][col - 1];
setSquareVisible(row - 1, col - 1);
}
}
}
display[row][col] = solution[row][col];
return true;
}
else
return false;
}
```

- 11 Views
- Tags: none (add)