目了,因为那些选项已经由Games菜单提供了。
|
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); } private void init(GameMIDlet parent) { this.parent = parent; this.addCommand(back); this.setCommandListener(this); //These are just a examples for the game specific options this.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.getSelectedIndex(); switch (idx) { case 0: //TODO break; case 1: //TODO break; case 2: //TODO break; case 3: parent.setDisplayable(def); break; //More if needed default: break; } } } } |
5 高分屏幕
当用户从主菜单中选择"High scores"选项的时候,高分就会显示出来。高分是显示在全屏画布(FullCanvas)实例上的。分数应该在一个屏幕上就显示完,而不要卷动页面,因为这样会给用户带来麻烦。
当然了,高分屏幕也可能会包含一些图片或者动画。用户应该能够通过按下左功能键、右功能键、数字键或者Send键返回主菜单。这个例子不提供任何处理高分的机制。处理高分的两种典型的方法是通过使用记录管理服务(RMS)永久保存分数或者通过HTTP连接把高分保存到服务器中。下面的代码是高分的框架。
|
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 screen parent.setDisplayable(menu); } } } |
6 教学屏幕
当用户从主菜单中选择"Instructions"条目的时候,就会显示出游戏的规则。游戏规则文本放置在Form实例中。Form中应该包含用于进入下一条教学规则的命令(例如,标签"More")和回到主菜单的命令(例如,标签"Back")。"More"一般由左功能键控制,而"Back"由右功能键控制。如果教学规则里包含动画,那么这些动画应该使用全屏画布(FullCanvas)来显示。按下左功能键将跳过动画进入下一个教学屏幕。按下右功能键,用户将从动画中回到主菜单。键End将结束应用程序。下面的代码是文字教学规则和动画的框架。
|
//Text instructions. Text can be written in constructor or in own method. //Developer should remember that also instruction texts should be //internationalized import javax.microedition.lcdui.*; public class Instructions extends Form implements CommandListener { //Command for going next instruction if needed private Command more = new Command( Resources.getString(Resources.ID_GAME_MORE), Command.OK, 1); //Command for going back to the main menu private Command back = new Command("", Command.BACK, 2); private GameMIDlet parent = null; private MainMenu menu = null; public Instructions(String title, GameMIDlet parent, MainMenu menu) { 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 e.g animation parent.setDisplayable(new InstructionAnimation(parent)); } else if (p0 == back) { parent.setDisplayable(menu); } } } //Instruction animation import 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 screen parent.setDisplayable(new MainMenu( Resources.getString ( Resources.ID_GAME_NAME), List.IMPLICIT, parent)); } } } |
7关于(About)屏幕
关于(About)屏幕显示游戏制作公司的消息文本或标志。当用户从主菜单中选择"About"选项的时候,就会启动这个屏幕。和教学规则页面一样,关于屏幕页面如果只需要文本信息的话,那么可以使用Form来实现。如果需要图像或动画,那么应该使用Canvas或FullCanvas。
|
//Text "About" code skeleton import javax.microedition.lcdui.*; public class About extends Form implements CommandListener { //Command for going back to the main menu private 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 commandAction(Command p0, Displayable p1) { if (p0 == back) { parent.setDisplayable(menu); } } } |