📄 基于nokia手机的移动游戏开发(3).htm
字号:
<TBODY>
<TR>
<TD align=middle colSpan=2><BR>
<DIV style="FONT-SIZE: 18pt; COLOR: #990000; FONT-FAMILY: 楷体_GB2312"
align=center><B>Java手机游戏开发实例</B></DIV><BR>
<DIV style="FONT-SIZE: 18px; COLOR: #990000; FONT-FAMILY: ; 宋体: "
align=center>基于Nokia手机的移动游戏开发(3)</DIV>
<DIV
style="PADDING-RIGHT: 10px; PADDING-LEFT: 10px; FONT-SIZE: 10.5pt; COLOR: black; LINE-HEIGHT: 180%"
align=left><BR>
<P><SPAN
class=f14> <STRONG>二、实现游戏的步骤</STRONG><BR><BR> 下图显示的是一个游戏MIDlet在成功安装和运行之后用户界面状态的典型的变化流程。我们想通过一个游戏者的视角来阐述开发移动游戏的过程。<BR></SPAN></P><SPAN
class=f14>
<P align=center><BR><IMG src="基于Nokia手机的移动游戏开发(3).files/1101782010-1.jpg"
align=baseline border=0><BR>图3 用户界面状态图表<BR></P>
<P><BR> 1
开始游戏<BR><BR> 在用户启动MIDlet之后,将显示游戏特定的闪动屏幕。闪动屏幕是FullCanvas的一个实例。它可用于显示一个公司的标志或者用动画形式介绍游戏。除了End键以外的所有键盘事件(MIDlet可用的)都可以跳过闪动屏幕并显示主菜单。还应该设置一个时间限定,能够在一定的时间过后自动跳出闪动屏幕进入游戏屏幕。<BR>GameMIDlet类是游戏的基本类;它处理MIDlet的生命周期并且处理游戏显示。下面的代码是闪动屏幕和游戏MIDlet类的构架。<BR><BR></P>
<TABLE width="100%" bgColor=#ffffff>
<TBODY>
<TR>
<TD>//Skeleton for the base class of game<BR>import
javax.microedition.midlet.*;<BR>import
javax.microedition.lcdui.*;<BR>public class GameMIDlet extends
MIDlet {<BR> private Display display = null;<BR> //Splash screen
that starts the application<BR> private SplashFullCanvas
splash;<BR> public GameMIDlet() {<BR> splash = new
SplashFullCanvas(this);<BR> }<BR> protected void startApp() throws
MIDletStateChangeException {<BR> if (display == null)
{<BR> display = Display.getDisplay(this);<BR> }<BR> //splash
screen to the
display<BR> setDisplayable(splash);<BR> }<BR> protected void
pauseApp() {<BR>}<BR><BR> protected void destroyApp(boolean
p0)<BR> throws MIDletStateChangeException {<BR> }<BR><BR> public
void setDisplayable(Displayable dl)
{<BR> display.setCurrent(dl);<BR> }<BR>}<BR><BR>//Skeleton for the
splash screen in Nokia Java Game<BR>import
javax.microedition.lcdui.*;<BR>import java.util.Timer;<BR>import
java.util.TimerTask;<BR>import com.nokia.mid.ui.*;<BR><BR>public
class SplashFullCanvas extends FullCanvas {<BR> private GameMIDlet
parent = null;<BR> private MainMenu menu = null;<BR> private Timer
timer = null;<BR> public SplashFullCanvas(GameMIDlet parent)
{<BR> this.parent = parent;<BR> menu = new
MainMenu(<BR> Resources.getString(Resources.ID_GAME_NAME),<BR> List.IMPLICIT,
parent);<BR> startTimer();<BR> }<BR>protected void paint(Graphics
g) {<BR> //Do the splash screen here<BR>}<BR>protected void
keyPressed(int keyCode) {<BR> timer.cancel();<BR> timer =
null;<BR> //All key events received set the main menu to the
screen<BR> parent.setDisplayable(menu);<BR>}<BR><BR>//Timer for the
splash screen. Main menu is set to the display<BR>//after 5
seconds.<BR>private void startTimer() {<BR> TimerTask task =new
TimerTask() {<BR> public void run()
{<BR> parent.setDisplayable(menu);<BR> }<BR> };<BR> timer = new
Timer();<BR> timer.schedule(task,
5000);<BR>}<BR>}</TD></TR></TBODY></TABLE><BR> 2
主菜单(MainMenu)屏幕<BR><BR> 主菜单是包含游戏特定选项的固有目录("Continue"、"New
game"、"Options"、"High scores"、"Instructions"、"About"和"Exit
game")。"Continue"只有在游戏被暂停的时候才能被显示。当"Continue"显示的时候,它必须是目录列表的第一个元素。主菜单的标题必须是游戏的名称。下面的代码是主菜单的框架。<BR><BR>
<TABLE width="100%" bgColor=#ffffff>
<TBODY>
<TR>
<TD>//Skeleton for the main menu<BR>import
javax.microedition.lcdui.*;<BR>public class MainMenu extends List
implements CommandListener {<BR> private GameMIDlet parent =
null;<BR> private GameFullCanvas game = null;<BR> public
MainMenu(String p0, int p1, String[] p2, Image[] p3,<BR> GameMIDlet
parent) {<BR> super(p0, p1, p2,
p3);<BR> init(parent);<BR> }<BR> public MainMenu(String p0, int p1,
GameMIDlet parent) {<BR> super(p0,
p1);<BR> init(parent);<BR> }<BR> public void init(GameMIDlet
parent) {<BR> this.parent =
parent;<BR> this.setCommandListener(this);<BR> //if game paused
then "Continue" should be available in<BR> //selection list<BR> if
(game != null && game.isPaused())
{<BR> if(!(this.getString(0).equals(<BR> new
String(Resources.getString(<BR> Resources.ID_GAME_CONTINUE)))))
{<BR> this.insert(0,<BR> Resources.getString(Resources.ID_GAME_CONTINUE),<BR> null);<BR> }<BR> this.setSelectedIndex(0,true);<BR> }<BR> else
{<BR> //These must be with or without
icons<BR> this.append(Resources.getString(Resources.ID_GAME_NEW),
null);<BR> this.append(Resources.getString(Resources.ID_GAME_OPTIONS),null);<BR> this.append(Resources.getString(<BR> Resources.ID_GAME_HIGHSCORES),
null);<BR> this.append(Resources.getString(<BR> Resources.ID_GAME_INSTRUCTIONS),
null);<BR> this.append(Resources.getString(Resources.ID_GAME_ABOUT),
null);<BR> this.append(Resources.getString(Resources.ID_GAME_EXIT),
null);<BR> }<BR> }<BR> public void commandAction(Command p0,
Displayable p1) {<BR> List lis = (List) p1;<BR> String selected
=<BR> lis.getString(lis.getSelectedIndex());<BR> if
(selected.equals(Resources.getString(Resources.ID_GAME_NEW)))
{<BR> game = new GameFullCanvas(parent,
this);<BR> parent.setDisplayable(game);<BR> }<BR> else if
(selected.equals(<BR> Resources.getString(Resources.ID_GAME_OPTIONS)))
{<BR> parent.setDisplayable(<BR> new
OptionList(Resources.getString(Resources.ID_GAME_OPTIONS),<BR> List.IMPLICIT,<BR> parent,
this));<BR> }<BR> else if
(selected.equals(<BR> Resources.getString(Resources.ID_GAME_HIGHSCORES)))
{<BR> parent.setDisplayable(new HighScore(parent,
this));<BR> }<BR> else if
(selected.equals(<BR> Resources.getString(Resources.ID_GAME_INSTRUCTIONS)))
{<BR> parent.setDisplayable(<BR> new
Instructions(<BR> Resources.getString(Resources.ID_GAME_INSTRUCTIONS),parent,this));<BR> }<BR> else
if
(selected.equals(<BR> Resources.getString(Resources.ID_GAME_ABOUT)))
{<BR> parent.setDisplayable(<BR> new
About(<BR> Resources.getString(Resources.ID_GAME_ABOUT),<BR> parent,<BR> this));<BR> }<BR> else
if
(selected.equals(<BR> Resources.getString(Resources.ID_GAME_EXIT)))
{<BR> parent.notifyDestroyed();<BR> }<BR> else if
(selected.equals(<BR> Resources.getString(Resources.ID_GAME_CONTINUE)))
{<BR> if (game != null)
{<BR> game.gameContinue();<BR> parent.setDisplayable(game);<BR> }<BR> }<BR> }<BR>}</TD></TR></TBODY></TABLE></SPAN><BR><BR></DIV></TD></TR>
<TR>
<TD class=center01>
<DIV align=center>来源:天极网 作者:
<DIV></DIV></DIV></TD>
<TD class=center01 width=280>
<DIV align=center><FONT color=#0000ff><A
href="http://act.it.sohu.com/book/chapter.php?id=461&volume=4&chapter=8">上一页</A></FONT>
<FONT color=#0000ff><A
href="http://act.it.sohu.com/book/serialize.php?id=461">回书目</A></FONT>
<FONT color=#0000ff><A
href="http://act.it.sohu.com/book/chapter.php?id=461&volume=4&chapter=10">下一页</A></FONT>
</DIV></TD></TR></TBODY></TABLE>
<TABLE>
<TBODY>
<TR>
<TD width=760>
<TABLE height=10 cellSpacing=0 cellPadding=0 width=760 border=0>
<TBODY>
<TR>
<TD></TD></TR></TBODY></TABLE><!------------ 评论 ---------------->
<TABLE cellSpacing=0 cellPadding=0 width=760 border=0>
<TBODY>
<TR>
<TD><IFRAME id=vs src="基于Nokia手机的移动游戏开发(3).files/comment_list1.htm"
frameBorder=0 width="100%"
scrolling=no></IFRAME></TD></TR></TBODY></TABLE><BR>
<SCRIPT language=javascript>function CheckNetwordForm(theForm){ if("" == theForm.content.value) { alert("写两句吧~~"); theForm.content.focus(); return false; } var index; for(index=0;index<theForm.content.value.length;index++) { if(" " != theForm.content.value.charAt(index)) break; } if(index == theForm.content.value.length) { alert("写两句吧~~"); theForm.content.focus(); return false; } if (theForm.content.value.length>100){ alert("评论字数不能超过100哦"); theForm.content.focus(); return false; } return true;}</SCRIPT>
<!------------------ 评论 --------------->
<FORM name=netword onsubmit="javascript: return CheckNetwordForm(this);"
action=insertnetword.php method=post>
<TABLE cellSpacing=0 cellPadding=0 width=760 border=0>
<TBODY>
<TR>
<TD class=text6 height=25> 给此书打分:<A name=1></A> <SELECT
name=score> <OPTION value=5 selected>非常好</OPTION> <OPTION
value=4>还凑合</OPTION> <OPTION value=3>一般吧</OPTION> <OPTION
value=2>不太行</OPTION> <OPTION value=1>太差了</OPTION></SELECT>
用户名: <INPUT id=id type=hidden value=461 name=id> <INPUT type=hidden
value=/book/chapter.php?id=461&volume=4&chapter=9
name=backurl> <INPUT id=username maxLength=20 name=username> <FONT
color=#666666>*评论字数请控制在一百字以内</FONT> </TD></TR></TBODY></TABLE><BR> <TEXTAREA id=description name=content rows=4 wrap=off cols=80></TEXTAREA>
<INPUT type=submit value=提交 name=Submit>
</FORM></TD></TR></TBODY></TABLE></TD></TR></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width=760 border=0>
<TBODY>
<TR>
<TD width=1003 background=基于Nokia手机的移动游戏开发(3).files/t_bj01.gif
height=9><IMG height=1 src="" width=1></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width=760 bgColor=#ffffff border=0>
<TBODY>
<TR>
<TD>
<HR width=760 noShade SIZE=1>
</TD></TR>
<TR>
<TD align=middle><A class=black href="http://www.chinaren.com/"
target=_blank>ChinaRen</A> - <A class=black
href="http://big5.www.sohu.com/" target=_blank>繁体版</A> - <A class=black
href="http://hr.sohu.com/hrm.html" target=_blank>搜狐招聘</A> - <A class=black
href="http://add.sohu.com/" target=_blank>网站登录</A> - <A class=black
href="http://help.sohu.com/" target=_blank>帮助中心</A> - <A class=black
href="http://book.news.sohu.com/onClick=this.style.behavior='url(#default#homepage)';this.setHomePage('http://www.sohu.com');return"
target=_blank false;>设置首页</A> - <A class=black
href="http://adinfo.sohu.com/" target=_blank>广告服务</A> - <A class=black
href="http://www.sohu.com/about/lianxi.htm" target=_blank>联系方式</A> - <A
class=black href="http://www.sohu.com/about/privacy.html"
target=_blank>保护隐私权</A> - <A class=black href="http://www.sohu.com/about/"
target=_blank>About SOHU</A> - <A class=black
href="http://www.sohu.com/about/" target=_blank>公司介绍</A><BR><SPAN
class=eng>Copyright © 2004 Sohu.com Inc. All rights reserved. 搜狐公司
版权所有</SPAN> </TD></TR></TBODY></TABLE></CENTER><!-- START NNR Site Census V5.1 --><!-- COPYRIGHT 2004 Nielsen // Netratings -->
<SCRIPT language=JavaScript type=text/javascript>
<!--
var _rsCI="cn-sohu";
var _rsCG="0";
var _rsDT=0;
var _rsDU=0;
var _rsDO=0;
var _rsX6=0;
var _rsSI=escape(window.location);
var _rsLP=location.protocol.indexOf('https')>-1?'https:':'http:';
var _rsRP=escape(document.referrer);
var _rsND=_rsLP+'//secure-cn.imrworldwide.com/';
if (parseInt(navigator.appVersion)>=4)
{
var _rsRD=(new Date()).getTime();
var _rsSE=1;
var _rsSV="";
var _rsSM=0.01;
_rsCL='<scr'+'ipt language="JavaScript" type="text/javascript" src="'+_rsND+'v51.js"><\/scr'+'ipt>';
}
else
{
_rsCL='<img src="'+_rsND+'cgi-bin/m?ci='+_rsCI+'&cg='+_rsCG+'&si='+_rsSI+'&rp='+_rsRP+'">';
}
document.write(_rsCL);
//-->
</SCRIPT>
<NOSCRIPT><IMG alt="" src="基于Nokia手机的移动游戏开发(3).files/m.gif"> </NOSCRIPT><!-- END NNR Site Census V5.1 -->
<SCRIPT language=JavaScript
src="基于Nokia手机的移动游戏开发(3).files/nnselect.js"></SCRIPT>
<NOSCRIPT><IMG height=1 src="" width=1> </NOSCRIPT></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -