我的朋友正在制作一个扫雷克隆,他让我帮忙解决当您单击非地雷/非数字“空白”方块时,它会显示所有相邻空白的部分。以下是我写的代码。我无法弄清楚为什么它永远不会解决。
我的基本情况应该是当 for 循环完全执行并且 if 语句永远不会返回 true 时。
有什么我想念的吗?
顺便说一句,这是在java中。另外,我告诉他应该将整个按钮状态更改分配给一个方法:p
public void revealAdjacentNulls(int r, int c)
{
int ir, ic;
//literal edge cases :P
int rmax = (r == 15) ? r : r + 1;
int cmax = (c == 15) ? c : c + 1;
//check all spaces around button at r,c
for(ir = (r==0) ? 0 : r-1; ir <= rmax; ir++){
for (ic = (c==0) ? 0 : c-1; ic <= cmax; ic++){
//if any are blank and uncovered, reveal them, then check again around the blanks
if (buttons[ir][ic].value == 0 && buttons[ir][ic].isCovered == false)
{
buttons[ir][ic].setEnabled(false); //number uncovered
buttons[ir][ic].setBackground(Color.blue);
buttons[ir][ic].setText(Character.toString(buttons[ir][ic].value));
buttons[ir][ic].isCovered = false;
revealAdjacentNulls(ir, ic);
}
}
}
}