所以,我正在制作一个简单的猜谜游戏,但是当用户按下取消按钮时,程序不会退出循环。以下是循环代码:
while(playAgain = true){
int n = JOptionPane.showConfirmDialog(null, fields, "Number guessing game", JOptionPane.CANCEL_OPTION);
if(n == JOptionPane.CANCEL_OPTION){
playAgain = false;
}
int randomNumber = randomNumber();
String guess = input.getText();
compare(randomNumber, Integer.parseInt(guess));
}