Mobile game development stepbread based on Nokia mobile phone (4)

xiaoxiao2021-03-06  14

3 Game Screen If the user selects "New Game" from the main menu, start the game and display the game screen. The game screen uses full-screen drafting (fullcanvas). If you press any function key, the user interface must return to the main menu and should be paused. Other buttons are valid for the game. Note: The game should not create tags for any function keys on the screen. If you must use a function key tag, the application should use the default Canvas screen Commands. The sample code does not solve problems such as threads and thread safety, which must pay special attention when designing. The following code is the framework of the game screen.

import javax.microedition.lcdui *;. import com.nokia.mid.ui *;. public class GameFullCanvas extends FullCanvas {private GameMIDlet parent = null; private MainMenu menu = null; private boolean gamePaused = false; public GameFullCanvas (GameMIDlet parent, MainMenu menu) {this.parent = parent; this.menu = menu;} protected void paint (Graphics g) {// Paint the game screen here} protected void keyPressed (int keyCode) {if (keyCode == KEY_SOFTKEY1 || keyCode == KEY_SOFTKEY2 || keyCode == KEY_SOFTKEY3) {gamePaused = true; // main menu to the screenmenu.init (parent); parent.setDisplayable (menu);}} public void gameContinue () {gamePaused = false;} public boolean ISPAUSED () {Return GamePaused;}} 4 Game Options Screen Users can change specific game options by selecting the "Options" option in the main menu. The Options list is an intrinsic list that contains an entry for processing game settings, such as sound, vibration (see one, 8), tone, etc. If you want to go back to the main menu, you need to use the back command. The following code is the framework of the Options list. Note: If the game is installed to the Games menu, you don't need a Lights / Sounds setting entry because those options have been provided by the Games menu.

import javax.microedition.lcdui *;. public class OptionList extends List implements CommandListener {private GameMIDlet parent = null; private MainMenu menu = null; private KeyDefinitions def = null; private Command back = new Command ( "", Command.BACK, 2 ); public optionList (String P0, INT P1, String [] P2, Image [] P3, Gamemidlet Parent, MainMenu Menu) {Super (P0, P1, P2, P3); this.Menu = MENU; INIT (PARENT); } Public optionList (String P0, INT P1, Gamemidlet Parent, MainMenu Menu) {Super (P0, P1); this.Menu = MENU; Init (PARENT); this.addCommand (back); this.setCommandListener (this); // These are just a examples for the game specific optionsthis.append (Resources.getString (Resources.ID_GAME_LEVEL), null); this.append (Resources.getString (Resources .ID_GAME_SOUNDS), null); this.append (Resources.getString (Resources.ID_GAME_VIBRA), null);} public void commandAction (Command p0, Displayable p1) {if (p0 == back) {parent.setDisplayable (menu); } else {list lis = (list) P1; int idx = lis.getSelectedIndIndex (); switch (idx) {case 0: // Todobreak; Case 1: // Todobreak; Case 2: // Todobreak; Case 3: Parent.SetDisplayAble (DEAK; / / More if neededdefault: break;}}}} author: wayne compile posted from: yesky.com author Blog:

http://blog.9cbs.neet/mobilechannel/

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

New Post(0)