Java Tic-Tac-Toe游戏错误
我编写了一个tic-tac-toe游戏,它编译得很好,运行得很好,但是如果你点击左上角的框,它会自动显示X赢了。这是董事会上唯一一项这样做的运动。我不知道我在决定胜利者时做错了什么。如果你想看到更多的代码,完整的代码是Java Tic-Tac-Toe游戏错误,java,Java,我编写了一个tic-tac-toe游戏,它编译得很好,运行得很好,但是如果你点击左上角的框,它会自动显示X赢了。这是董事会上唯一一项这样做的运动。我不知道我在决定胜利者时做错了什么。如果你想看到更多的代码,完整的代码是 不要使用==和比较字符串=。使用equals()和!改为等于() 请参见不要使用==和比较字符串=。使用equals()和!改为等于() 请参见使用.equals而不是==。不确定哪个条件是指左上角的框。左上角的框是按钮1,我应该说得更清楚。我仍然说我们需要一个投票关闭选项,即“
不要使用
==
和比较字符串=代码>。使用equals()
和!改为等于()
请参见不要使用==
和比较字符串=代码>。使用equals()
和!改为等于()
请参见使用.equals而不是==
。不确定哪个条件是指左上角的框。左上角的框是按钮1,我应该说得更清楚。我仍然说我们需要一个投票关闭选项,即“您不使用==在java中比较字符串”。使用.equals而不是==
。不确定哪个条件引用了左上角的框。左上角的框是button1,我应该更清楚地说明这一点。我仍然说我们需要一个投票关闭选项,它是“在java中不使用==来比较字符串”。好吧,那么如果((button1.getText()).equals()(button2.getText())和((button2.getText()).equals())是这样的(button3.getText())&&&(button1.getText())!equals()){win=true;}好吧,如果((button1.getText()).equals()(button2.getText())&&(button2.getText())。equals()(button3.getText())&&(button1.getText())!equals()。{win=true;}
//Determine who won
if(button1.getText() == button2.getText()
&& button2.getText() == button3.getText()
&& button1.getText() != "")
{
win = true;
}
else if(button4.getText() == button5.getText()
&& button5.getText() == button6.getText()
&& button4.getText() != "")
{
win = true;
}
else if(button7.getText() == button8.getText()
&& button8.getText() == button9.getText()
&& button7.getText() != "")
{
win = true;
}
else if(button1.getText() == button4.getText()
&& button4.getText() == button7.getText()
&& button1.getText() != "")
{
win = true;
}
else if(button2.getText() == button5.getText()
&& button5.getText() == button8.getText()
&& button2.getText() != "")
{
win = true;
}
else if(button3.getText() == button6.getText()
&& button6.getText() == button9.getText()
&& button3.getText() != "")
{
win = true;
}
else if(button1.getText() == button5.getText()
&& button5.getText() == button9.getText()
&& button1.getText() != "")
{
win = true;
}
else if(button3.getText() == button5.getText()
&& button5.getText() == button7.getText()
&& button1.getText() != "")
{
win = true;
}
else
{
win = false;
}
if (win == true)
{
JOptionPane.showMessageDialog(null,
letter + " Wins!");
}
else if (count == 9 && win == false)
{
JOptionPane.showMessageDialog(null,
"Tie Game!");
}
}
}