任务是创建一个黑白棋游戏。除了涉及更改多个芯片的动作外,我可以正常工作
x o o o o o o @ <-- the @ is x's move that crashes the game.
,在这种情况下程序崩溃。坠机发生在某处isPlayable()
。
我哪里错了?
//there are 7 more such methods for different directions
// (down, left, right, diagonals).
public void searchN(int x, int y, int increment){
if(x-increment>=0){
if(this.isPlayed(x-increment,y)){
if(increment>1 && chips[x-increment][y]==turnColor){
//turnColor is an int value 1 or 2
// (0 represents unplayed space in chips[][])
// 1 corresponding to white, 2 corresponding to black.
playable[0] = true;
leads[0] = false;
} else {
if(chips[x-increment][y]!=turnColor){
leads[0]=true;
}
}
}else
leads[0]=false;
}else
leads[0]=false;
}
public boolean isPlayable(int x, int y){
this.searchN(x,y,1); //7 other directions are searched
while(leads[0]||leads[1]||leads[2]||leads[3]||leads[4]
||leads[5]||leads[6]||leads[7]){
int i = 2;
if(leads[0]) // 7 other directions are searched given that their marker is true.
this.searchN(x,y,i);
}
if(playable[0]||playable[1]||playable[2]||playable[3]||playable[4]
||playable[5]||playable[6]||playable[7])
return true;
else
return false;
}