Second, the step of implementing the game The figure below shows a typical change process of a game MIDlet after successful installation and running. We want to explain the process of developing mobile games through a player's perspective. Figure 3 User Interface Status Chart 1 Start the game After the user starts the MIDlet, the game-specific flash screen will be displayed. The flash screen is an instance of Fullcanvas. It can be used to display a company's logo or to introduce the game with animation. In addition to all keyboard events other than the END key (MIDLET available) can skip the flash screen and display the main menu. You should also set a time limit that automatically jumps out of the flash screen to the game screen after a certain amount of time. The Gamemidlet class is the basic class of the game; it handles the life cycle of the MIDlet and handles the game display. The following code is the framework of the flash screen and the game MIDlet class.
// Skeleton for the base class of gameimport javax.microedition.midlet *;. Import javax.microedition.lcdui *;. Public class GameMIDlet extends MIDlet {private Display display = null; // Splash screen that starts the application private SplashFullCanvas splash; public GameMIDlet () {splash = new SplashFullCanvas (this);} protected void startApp () throws MIDletStateChangeException {if (display == null) {display = Display.getDisplay (this);} // splash screen to the display setDisplayable (splash );} protected void pauseApp () {} protected void destroyApp (boolean p0) throws MIDletStateChangeException {} public void setDisplayable (Displayable dl) {display.setCurrent (dl);}} // Skeleton for the splash screen in Nokia Java Gameimport javax .microedition.lcdui *;. import java.util.Timer; import java.util.TimerTask; import com.nokia.mid.ui *;. public class SplashFullCanvas extends FullCanvas {private GameMIDlet parent = null; private MainMenu menu = null; PRIVATE TIMER TIMER = NULL; Public Splashfu llCanvas (GameMIDlet parent) {this.parent = parent; menu = new MainMenu (Resources.getString (Resources.ID_GAME_NAME), List.IMPLICIT, parent); startTimer ();} protected void paint (Graphics g) {// Do the splash screen here} protected void keyPressed (int keyCode) {timer.cancel (); timer = null; // All key events received set the main menu to the screen parent.setDisplayable (menu);} // Timer for the splash screen MAIN MENU IS Set To the Display // After 5 Seconds.private Void StartTimer () {Timertask Task = New Timertask () {Public Void Run () {Parent.SetDisplayAble (MENU);}}; Timer = New Timer () Timer.Schedule (Task, 5000);} 2 Main Menu screen main menu is an intrinsic directory containing the game specific options (
"Continue", "New Game", "Options", "High Scores", "Instructions", "About", and "EXIT GAME"). "Continue" is only displayed when the game is suspended. When "Continue" is displayed, it must be the first element of the list of directories. The title of the main menu must be the name of the game. The following code is the framework of the main menu.
// Skeleton for the main menuimport javax.microedition.lcdui *;. Public class MainMenu extends List implements CommandListener {private GameMIDlet parent = null; private GameFullCanvas game = null; public MainMenu (String p0, int p1, String [] p2, Image [] P3, Gamemidlet Parent) {Super (P0, P1, P2, P3); INIT (PARENT); PUBLIC MAINMENU (String P0, INT P1, GAMEMIDLET PARENT) {Super (P0, P1); Init (PARENT); } public void init (GameMIDlet parent) {this.parent = parent; this.setCommandListener (this);! // if game paused then "Continue" should be available in // selection list if (game = null && game.isPaused ( )) {If (! (0) .Equals (resources.id_game_continue)))))))))))))))))))))))))))))))) {this.Insert (0, resources.getstring (resources.id_game_continue), null; } This.setSelectedIndex (0, true);} else {// THESE MUST BE with or without icons this.append (resources.id_game_new), null; this.append (resources.gets tring (Resources.ID_GAME_OPTIONS), null); this.append (Resources.getString (Resources.ID_GAME_HIGHSCORES), null); this.append (Resources.getString (Resources.ID_GAME_INSTRUCTIONS), null); this.append (Resources.getString ( Resources.ID_GAME_ABOUT), null); this.append (Resources.getString (Resources.ID_GAME_EXIT), null);}} public void commandAction (Command p0, Displayable p1) {List lis = (List) p1; String selected = lis. GetString (Lis.getSelectedIndex ()); if (resources.equals (resources.id_game_new))) {game = new gamefullcanvas (parent, this); parent.setdisplayable (game);
} Else if (selected.equals (Resources.getString (Resources.ID_GAME_OPTIONS))) {parent.setDisplayable (new OptionList (Resources.getString (Resources.ID_GAME_OPTIONS), List.IMPLICIT, parent, this));} else if (selected .equals (Resources.getString (Resources.ID_GAME_HIGHSCORES))) {parent.setDisplayable (new HighScore (parent, this));} else if (selected.equals (Resources.getString (Resources.ID_GAME_INSTRUCTIONS))) {parent.setDisplayable ( new Instructions (Resources.getString (Resources.ID_GAME_INSTRUCTIONS), parent, this));} else if (selected.equals (Resources.getString (Resources.ID_GAME_ABOUT))) {parent.setDisplayable (new About (Resources.getString (Resources. ID_GAME_ABOUT), parent, this));} else if (selected.equals (Resources.getString (Resources.ID_GAME_EXIT))) {parent.notifyDestroyed ();} else if (selected.equals (Resources.getString (Resources.ID_GAME_CONTINUE) )) {IF ! Game = null) {game.gameContinue (); parent.setDisplayable (game);}}}} Author: wayne compile posted from: yesky.com Author Blog:
http://blog.9cbs.neet/mobilechannel/