OptionPanes and keyboard inputs/exitting program (game quit)
Hi there,
Im implementing my game an assignment and Ive come across a problem that I cant seem to solve. Ive created an option pane that, in a win or lose situation, allows the user to restart or quit the game- the restarting is simple enough in that if the value of the option pane = 0 then it executes the resetGame method, the trouble comes with the quit option. At present it is linked to the resetGame but what I would really like is for it to have the same effect as pressing the 'S' key in the game (i.e. stop the game and display the main screen). Is there any way to do this? Is there like a quit to previous panel option, go back a screen, anything that can exit the game- as pressing s on the keyboard stops the game and goes back to the main screen.
The code in question is;
// make munchies move down the screen
for (int i = 0; i < NUM_MUNCHIES; i++) {
if (munchieDirection == 1){
munchieYPos = munchieYPos + munchieSpeed;
if (munchieYPos > (boardHeight - munchieHeight)){// if the munchies touch the bottom the create game end situation
gameLoseSound.play();
int value1 = JOptionPane.showOptionDialog(null, "Would you like to restart the game? If not, press Quit and type S to stop the game.", "You Lose", JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null, new Object[]{"Restart", "Quit"}, "Restart");
if (value1 == 0){
resetGame();} else {
resetGame();}//change to quit value
}
}}
AND
// scoring and reset
if (score >= 5){
gameWinSound.play();
value = JOptionPane.showOptionDialog(null, "Would you like to restart the game? If not, press Quit and type S to stop the game.", "You Win", JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null, new Object[]{"Restart", "Quit"}, "Restart");
if (value == 0){
resetGame();} else {
resetGame();} //change to quit value
}
Any help on this matter would be much appreciated, as although my current method may suffice- its not 100% appropriate (in my opinion)

