5 High Score When the user selects the "high score" option from the main menu, the high score will appear. The high score is displayed on the full-screen dragavas instance. The score should be displayed on one screen without rolling the page, as this will bring trouble to the user. Of course, the high score may also contain some pictures or animations. Users should be able to return to the main menu by pressing the left function keys, right function keys, numbers or send keys. This example does not provide any mechanism for processing a high score. Two typical methods for processing high scores are to save the high scores into the server by using a record management service (RMS) permanently or through the HTTP connection. The following code is a high score.
import javax.microedition.lcdui *;. import com.nokia.mid.ui *;. public class HighScore extends FullCanvas {private GameMIDlet parent = null; private MainMenu menu = null; public HighScore (GameMIDlet parent, MainMenu menu) {this. parent = parent; this.menu = menu;} protected void paint (Graphics g) {// Paint the high scores here} public void keyPressed (int keyCode) {if (! keyCode = KEY_END) {// selection list to the screenparent .SetDisplayable (MENU);}}} 6 Teaching Screen When the user selects the "Instructions" entry from the main menu, the rule of the game will be displayed. The game rule text is placed in the Form instance. The form should contain commands for entering the next teaching rule (eg, tag "more") and back to the main menu (for example, the tag "back"). "More" is generally controlled by the left function key, and "back" is controlled by the right function key. If the teaching rules contain animations, these animations should be displayed using full screen drawing. Press the left function key to jump out the animation to the next teaching screen. Press Right Function keys to return from the animation to the main menu. The key END will end the application. The following code is a textual teaching rules and an animation framework.
. // Text instructions Text can be written in constructor or in ownmethod.//Developer should remember that also instruction texts should be // internationalizedimport javax.microedition.lcdui *;. Public class Instructions extends Form implements CommandListener {// Command for going next instruction if neededprivate Command more = new Command (Resources.getString (Resources.ID_GAME_MORE), Command.OK, 1); // Command for going back to the main menuprivate Command back = new Command ( "", Command.BACK, 2 ); private GameMIDlet parent = null; private MainMenu menu = null; public Instructions (String title, GameMIDlet parent, MainMenumenu) {super (title); this.parent = parent; this.menu = menu; this.addCommand (back); this.addCommand (more); this.setCommandListener (this);} public void commandAction (Command p0, Displayable p1) {if (p0 == more) {// go to the next if needed eg animationparent.setDisplayable (new InstructionAnimation ( PARENT));} else if (p0 == back) {parent.setdisplayable (menu);}}} // instruction animationImpor t javax.microedition.lcdui *;. import com.nokia.mid.ui *;. public class InstructionAnimation extends FullCanvas {private GameMIDlet parent = null; public InstructionAnimation (GameMIDlet parent) {this.parent = parent;} protected void paint ( Graphics g) {// Do the animation here} public void keyPressed (int keyCode) {if (keyCode == KEY_SOFTKEY1) {// go to the next instruction screen if needed} else if (keyCode == KEY_SOFTKEY2) {// selection List to the screenparent.setdisplayable (resources.id_game_name), list.implicit, parent);}}} 7 About the (About) screen About) screen display game creation company message text or logo . When the user selects the "About" option from the main menu, this screen will be launched.
Like the teaching rules page, if you only need text information, you can use Form to implement it. If image or animation is required, Canvas or Fullcanvas should be used. // Text "About" code skeletonimport javax.microedition.lcdui *;. Public class About extends Form implements CommandListener {// Command for going back to the main menuprivate Command back = new Command ( "", Command.BACK, 1); private GameMIDlet parent = null; private MainMenu menu = null; public About (String title, GameMIDlet parent, MainMenu menu) {super (title); this.parent = parent; this.menu = menu; this.addCommand (back); this .SETCOMMANDLISTENER (this);} public void command (Command P0, Displayable P1) {if (p0 == BACK) {parent.setdisplayable (menu);}}} 8 Exit From the main menu to choose "EXIT GAME" option to abort Games and release all resources. 9 Resources class Resources class is not a user interface class, which is different from the other classes described in this article. This class handles internationalization.
. / *** A simple class to simulate a resource bundle * Modify the contents of this class according to the * locales / languages you want your application to support * In your application, retrieve a string using code such as the * following.: *
* string s = resources.getstring; * code> pre> * copyright (c) 2002 Nokia Corporation * / public class resources {// identifiers for text strings. public static final int ID_GAME_NEW = 0; public static final int ID_GAME_OPTIONS = 1; public static final int ID_GAME_HIGHSCORES = 2; public static final int ID_GAME_INSTRUCTIONS = 3; public static final int ID_GAME_ABOUT = 4; public static final int ID_GAME_CONTINUE = 5; public static final int ID_GAME_BACK = 6; public static final int ID_GAME_MORE = 7; public static final int ID_GAME_EXIT = 8; public static final int ID_GAME_LEVEL = 9; public static final int ID_GAME_SOUNDS = 10; public static final int ID_GAME_VIBRA = 11; public static final int ID_GAME_NAME = 12; // List of supported Loca Les.// the strings are nokia-specific value // of the "microedition.locale" system property.private static final string [] supportedlocales = {"en", "FI-FI", "fr", "de"} !; // NOTE: default language must be the first one // for getString to work // Strings for each locale, indexed according to the // contents of supportedLocalesprivate static final String [] [] strings = {{ "New game" , "Settings", "High Scores", "INSTRUCTIONS", "About", "Continue", "BACK", "Level", "Sounds", "SHAKES", "Game Name "}, {"
UUSI PELI, "ASETUKSET", "Huipputulokset", "Peliohjeet", "Tietoja", "Jatka", "Poistu", "JATKA", "Poistu", "VAIKEUSASTE", "Peli? Net", "V? Rin? tehosteet "," Pelin Nimi "}, {" Nouveau JEU "," Paramètres "," Scores "," Instructions "," A Propos "," Continuer "," Retour "," Suite "," Sortir ", "Niveau", "Sons", "Vibrations", "JEU NOM"}, {"Neues Spiel", "Einstellungen", "Rekord", "Anleitung", "über", "Weiter", "Zurück", "Weiter "" Beenden "," Ebene "," Ton "," vibrationen "," spiel name "}; / *** gets a string for the given key. * @Param key integer key for string * @return the string * / public static string getString (int key) {string local = system.getProperty ("microedition.locale"); if (locale == null) {locale = new string ("); // use empty instead of null} // Find the index of the locale idint localeIndex = -1; for (int i = 0; i
http://blog.9cbs.neet/mobilechannel/