//主要代码
public static void main(String [] args){
//启动游戏板
initGame();
//start the game
do {
PlayerMove(Cplayer);
updategame(Cplayer, crow, ccol);
printboard();
//game over message
if (currentstate == you_win){
System.out.println("'X' Won!!");
else if (currentstate == comp_win)
System.out.println("'O' won!!");
else if (currentstate == draw)
System.out.println("It's a Draw :(");
}
答案 0 :(得分:0)
if (currentstate == you_win){
System.out.println("'X' Won!!");
else if (currentstate == comp_win)
System.out.println("'O' won!!");
else if (currentstate == draw)
System.out.println("It's a Draw :(");
}
看看这一行(我删除了一些无关的代码,以便更容易看到):
if (currentstate == you_win){
else if (currentstate == comp_win)
//...
}
以这种方式看,你能看出为什么这是不正确的吗?顺便说一句,这就是您应该始终使用{
和}
的原因。请改为if
... else
:
if (currentstate == you_win){
// ...
}
else if (currentstate == comp_win) {
// ...
}
//...
或者,更好的是,只需使用switch
声明:
switch (currentstate) {
case you_win:
System.out.println("'X' Won!!");
break;
case comp_win:
System.out.println("'O' won!!");
break;
case draw:
System.out.println("It's a Draw :(");
break;
}