分享
 
 
 

基于Nokia手机的移动游戏开发步步通(五)

王朝other·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

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

}

}

}

8 退出

从主菜单中选择"Exit game"选项来中止游戏并释放所有的资源。

9 Resources类

Resources类不是一个用户界面类,与本文中介绍的其他类不同。这个类处理国际化问题。

/**

* 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:

* <pre>

* <code>String s = Resources.getString(Resources.ID_GAME_NEW);

* </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 locales.

// The strings are Nokia-specific values

// 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 supportedLocales

private static final String[][] strings = {

{ "New game", "Settings", "High scores", "Instructions",

"About","Continue", "Back", "More", "Exit game",

"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 locale = System.getProperty("microedition.locale");

if (locale == null) {

locale = new String(""); // use empty instead of null

}

// find the index of the locale id

int localeIndex = -1;

for (int i = 0; i < supportedLocales.length; i++) {

if (locale.equals(supportedLocales[i])) {

localeIndex = i;

break;

}

}

// not found

if (localeIndex == -1) {

// defaults to first language, in this example English

return strings[0][key];

}

return strings[localeIndex][key];

}

}

作者:wayne编译 转贴自:yesky.com

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有