我目前正在开发 Java 版本的扫雷。当用户点击一个地雷或赢得游戏时,我想实现一个“是,没有”选项面板,该面板将用作“你想再玩一次”之类的功能。实现 no 很简单,但我在实现程序再次运行的 yes 选项时遇到问题,但在我的情况下,它只是运行程序的新实例而不关闭旧实例。建议?谢谢。
这是用户找到所有地雷并获胜的代码:
if (check == nomines)
{
endtime = System.nanoTime();
Component temporaryLostComponent = null;
JOptionPane.showMessageDialog(temporaryLostComponent, "Congratulations, you won! It took you " + (int)((endtime-starttime)/1000000000) + " seconds!");
int p = JOptionPane.showConfirmDialog(this, "Play again?","Minefield",JOptionPane.YES_NO_OPTION);
if (p == 1)
{
System.exit(0);
}
else
{
new Minefield();
}
}
}
最佳答案
使用 一边做循环,它使您的工作变得轻松..
do{
// your all operations...
// at last prompt yes or no ?
} while(choice.equalsIgnoreCase("yes"));
关于java - 再次运行程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20204005/