我正在制作一个 Java Mine Sweeper 程序。到目前为止,除了级联和显示之外,一切都很顺利。我不断收到 StackOverFlowError。有人可以看看并帮助我吗?谢谢!
public static char[][]revealCell(int xbox, int ybox, char blankboard [] [], char RevealedBoard [][]){
if( RevealedBoard[ybox][xbox]== 'B'){
blankboard[ybox][xbox]= 'B';
return blankboard;
}else if( RevealedBoard[ybox][xbox]== '1'){
blankboard[ybox][xbox]= '1';
return blankboard;
}
else if( RevealedBoard[ybox][xbox]== '2'){
blankboard[ybox][xbox]= '2';
return blankboard;
}else{
blankboard[ybox][xbox]= '-';
if( xbox== 0){ // left of the grid
if(ybox==0){
blankboard= revealCell(xbox+1, ybox, blankboard, RevealedBoard);
blankboard= revealCell(xbox, ybox+1, blankboard, RevealedBoard);
blankboard= revealCell(xbox+1, ybox+1, blankboard, RevealedBoard);
return blankboard;
}else if( ybox== 7){
blankboard= revealCell(xbox+1, ybox, blankboard, RevealedBoard);
blankboard= revealCell(xbox, ybox-1, blankboard, RevealedBoard);
blankboard= revealCell(xbox+1, ybox-1, blankboard, RevealedBoard);
return blankboard;
}else{
blankboard= revealCell(xbox+1, ybox, blankboard, RevealedBoard);
blankboard= revealCell(xbox, ybox-1, blankboard, RevealedBoard);
blankboard= revealCell(xbox +1, ybox-1, blankboard, RevealedBoard);
blankboard= revealCell(xbox, ybox+1, blankboard, RevealedBoard);
blankboard= revealCell(xbox+1, ybox+1, blankboard, RevealedBoard);
return blankboard;
}
}else if(xbox== 7){// right of the grid
blankboard= revealCell(xbox-1, ybox, blankboard, RevealedBoard);
if(ybox== 7){
blankboard= revealCell(xbox, ybox-1, blankboard, RevealedBoard);
blankboard= revealCell(xbox-1, ybox-1, blankboard, RevealedBoard);
return blankboard;
}else if( ybox==0){
blankboard= revealCell(xbox, ybox+1, blankboard, RevealedBoard);
blankboard= revealCell(xbox-1, ybox+1, blankboard, RevealedBoard);
return blankboard;
}else{
blankboard= revealCell(xbox-1, ybox-1, blankboard, RevealedBoard);
blankboard= revealCell(xbox-1, ybox+1, blankboard, RevealedBoard);
blankboard= revealCell(xbox, ybox-1, blankboard, RevealedBoard);
blankboard= revealCell(xbox, ybox+1, blankboard, RevealedBoard);
return blankboard;
}
}else{
if(ybox== 0){
blankboard= revealCell(xbox-1, ybox, blankboard, RevealedBoard);
blankboard= revealCell(xbox, ybox+1, blankboard, RevealedBoard);
blankboard= revealCell(xbox-1, ybox+1, blankboard, RevealedBoard);
return blankboard;
}else if( ybox==7){
blankboard= revealCell(xbox-1, ybox, blankboard, RevealedBoard);
blankboard= revealCell(xbox, ybox-1, blankboard, RevealedBoard);
blankboard= revealCell(xbox-1, ybox-1, blankboard, RevealedBoard);
return blankboard;
}else{
blankboard= revealCell(xbox, ybox-1, blankboard, RevealedBoard);
blankboard= revealCell(xbox-1, ybox-1, blankboard, RevealedBoard);
blankboard= revealCell(xbox+1, ybox-1, blankboard, RevealedBoard);
blankboard= revealCell(xbox-1, ybox+1, blankboard, RevealedBoard);
blankboard= revealCell(xbox, ybox+1, blankboard, RevealedBoard);
blankboard= revealCell(xbox-1, ybox, blankboard, RevealedBoard);
blankboard= revealCell(xbox+1, ybox, blankboard, RevealedBoard);
blankboard= revealCell(xbox+1, ybox+1, blankboard, RevealedBoard);
}
}
}
return blankboard;
}
}
revealCell 是我的方法,对于我在学校的实际课程,我们必须使用递归。我认为这是我们应该做的,但我遇到了错误。