Fields Summary |
---|
private WormPit | theGameCurrent game board for worm pit. |
private javax.microedition.lcdui.Command | exitCmdButton for exiting the game. |
private javax.microedition.lcdui.Command | levelCmdMenu item for changing game levels. |
private javax.microedition.lcdui.Command | startCmdMenu item for starting a new game. |
private javax.microedition.lcdui.Command | restartCmdMenu item to restart another game. |
private javax.microedition.lcdui.Command | audioOnCmdEnable audio. |
private javax.microedition.lcdui.Command | audioOffCmdDisable audio. |
private javax.microedition.lcdui.Command | cancelCmdMenu item to cancel current pausedmenu dialog. |
private javax.microedition.lcdui.Command | OKCmdMenu item to confirm current selected operation. |
Methods Summary |
---|
public void | commandAction(javax.microedition.lcdui.Command c, javax.microedition.lcdui.Displayable d)Respond to a commands issued on any Screen.
if (c == restartCmd) {
theGame.restart();
} else if (c == levelCmd) {
Item[] levelItem = {
new Gauge("Level", true, 9, theGame.getLevel())};
Form f = new Form("Change Level", levelItem);
f.addCommand(OKCmd);
f.addCommand(cancelCmd);
f.setCommandListener(this);
Display.getDisplay(this).setCurrent(f);
} else if (c == exitCmd) {
destroyApp(false);
notifyDestroyed();
} else if (c == startCmd) {
theGame.removeCommand(startCmd);
theGame.addCommand(restartCmd);
theGame.restart();
} else if (c == OKCmd) {
Form f = (Form)d;
Gauge g = (Gauge)f.get(0);
theGame.setLevel(g.getValue());
Display.getDisplay(this).setCurrent(theGame);
} else if (c == cancelCmd) {
Display.getDisplay(this).setCurrent(theGame);
} else if (c == audioOnCmd) {
/* Turn on Audio */
theGame.createAudioPlayer();
theGame.removeCommand(audioOnCmd);
theGame.addCommand(audioOffCmd);
} else if (c == audioOffCmd) {
/* Turn off Audio */
theGame.destroyAudioPlayer();
theGame.removeCommand(audioOffCmd);
theGame.addCommand(audioOnCmd);
}
|
protected void | destroyApp(boolean unconditional)Destroy must cleanup everything. Only objects exist so the GC
will do all the cleanup after the last reference is removed.
theGame.destroyAudioPlayer();
theGame.destroyGame();
Display.getDisplay(this).setCurrent((Displayable)null);
|
protected void | pauseApp()Pause signals the thread to stop by clearing the thread field.
If stopped before done with the iterations it will be restarted
from scratch later.
|
protected void | startApp()Start creates the thread to do the timing. It should return
immediately to keep the dispatcher from hanging.
Display.getDisplay(this).setCurrent(theGame);
try {
// Start the game in its own thread
Thread myThread = new Thread(theGame);
myThread.start();
} catch (Error e) {
destroyApp(false);
notifyDestroyed();
}
|