Analysis of Algorithm for Eating Snakes (5)

zhaozj2021-02-17  57

Analysis of Algorithm for Eating Snakes (5)

James @ www.chenshen.com

Wormmain

The most important class, inheriting from the MIDLET parent class and implements the CommandListener interface.

l protected void startapp ()

Implement the MIDlet parent class, first execute this function when the program is started

// Show

Display.getdisplay (this) .Setcurrent (THEGAME);

Try {

// Start the game thread

Thread mythread = new thread (thegame);

mythread.start ();

} catch (error e) {

DESTROYAPP (FALSE);

NOTIFYDESTROYED ();

l Public void CommandAction (Command C, Displayable D)

Accept and process user input events

// restart

IF (c == restartCMD) {

THEGAME.RESTART ();

}

/ / Change the difficulty level

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);

}

// Leave the game

IF (c == exitcmd) {

DESTROYAPP (FALSE);

NotifyDestroyed ();

}

// Start the game

IF (c == startcmd) {

THEGAME.Remmand (StartCMD);

THEGAME.ADDCOMMAND (RESTARTCMD);

THEGAME.RESTART ();

}

// Determine

IF (c == okcmd) {

Form f = (form) d;

Gauge g = (gauge) F.Get (0);

Thegame.SetLevel (g.getvalue ());

Display.getdisplay (this) .Setcurrent (THEGAME);

}

// cancel

IF (c == cancelcmd) {

Display.getdisplay (this) .Setcurrent (THEGAME);

}

// Open the sound

IF (c == audiooncmd) {

/ * Open sound * /

THEGAME.CREATEAUDIOPLAYER ();

THEGAME.Remmand (Audiooncmd);

THEGAME.ADDCOMMAND (AUDIOOFFCMD);

}

// Close the sound

IF (c == audiooffcmd) {

/ * Close the sound * /

THEGAME.DESTROYAUDIOPLAYER ();

THEGAME.REMOVECOMMAND (AUDIOOFFCMD);

THEGAME.ADDCOMMAND (AUDIOONCMD);

}

About the Author:

Shen Yachang, Senior Programmer, SCJP

Www.chenshen.com

Jinashen@benq.com

August 10, 2003

转载请注明原文地址:https://www.9cbs.com/read-29690.html

New Post(0)