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)

[2110 byte] By [5enorcojone5a] at [2007-11-26 13:23:56]
# 1

Got my main account working again now!

Still having trouble for this. Ive now completed the game- its all working, but I still havent solved the quit problem.

Is there anyway I can have the mouse click of the 'quit' button to flag up the same command as pressing the s key on the keyboard? Or is it possible to allow the quit button to allow the user to exit to the main menu?

PLEASE HELP! IM DESPERATE!

Thanx

Senor-cojones

Senor-cojonesa at 2007-7-7 17:57:04 > top of Java-index,Other Topics,Java Game Development...
# 2

> Is there anyway I can have the mouse click of the

> 'quit' button to flag up the same command as pressing

> the s key on the keyboard? Or is it possible to allow

> the quit button to allow the user to exit to the main

> menu?

Hard to say without seeing your code. If you already made it work when you press 's', then why can't you make it work by pushing a button?

CaptainMorgan08a at 2007-7-7 17:57:04 > top of Java-index,Other Topics,Java Game Development...
# 3

It appears ive fixed the problem very simply....

if (value1 == 0){

resetGame();} else {

Input.eventFlag = Input.STOP;

}

It was just a basic error. If i press S on the keyboard it executes... Input.STOP.... so now clicking the quit button as executes Input.STOP.. thank you for your help :)

Senor-cojonesa at 2007-7-7 17:57:04 > top of Java-index,Other Topics,Java Game Development...