そのため、マインスイーパ ゲームでカスケード リビールを行うメソッドの大部分があります。私はソリューションのボードと現在のグリッドの 1 つを持っています。しかし、問題は、0 スペースに遭遇すると、再帰呼び出しでスタック オーバーフロー エラーが発生することです。
誰にもアイデアはありますか?
public static void revealCell(int row, int col, char[][] grid, char[][] answers) {
System.out.println(row + " " + col);
if(row < 0|| row > 4){
System.out.println("bad");
return;
}
if(col < 0|| col > 4){
System.out.println("bad");
return;
}
if(answers[row][col] == 'B'){
grid[row][col] = answers[row][col];
return;
}
if(answers[row][col] == '1'||answers[row][col] == '2'||answers[row][col] == '3'||answers[row][col] == '4'||answers[row][col] == '5'){
grid[row][col] = answers[row][col];
return;
}
if(answers[row][col] == '0'){
System.out.println("go");
grid[row][col] = answers[row][col];
for(int i = row-1; i <= row +1; i++){
for(int j = col-1; j<= col +1;j++){
revealCell(i,j, grid, answers);
}
}
}
}