⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 j2me 2d小游戏入门之计时器.htm

📁 这是我整理的关于j2me飞机游戏制作材料,对入门有很大的帮助的
💻 HTM
📖 第 1 页 / 共 5 页
字号:
<DIV class=newsmallbox>J2ME 2D小游戏入门之计时器 </DIV>
<DIV class=clear1></DIV>
<DIV class=newsmall1box>
<DIV class=newtitle1>作者: favoyang </DIV>
<DIV class=newtitle2>出处: J2ME开发网 </DIV>
<DIV class=newtitle3>责任编辑: 方舟 </DIV>
<DIV class=newtitle4>[ 2004-11-13 13:14 ]</DIV></DIV>
<DIV class=clear1></DIV>
<DIV class=space2><SPAN id=ad5></SPAN></DIV><BR>
<DIV class=newmiddlebox style="OVERFLOW: hidden">
<DIV class=guanggao><SPAN id=ad4></SPAN></DIV>  六、计时器和奖惩与评价 
<BR><BR>  我们该加入我们的计时器了,我要从游戏开始时刻开始计时,并不断的更新到屏幕上,在游戏结束后计时器要停止工作。<BR><BR>  首先在初始化的时候将当前时刻记录下来:<BR><BR>
<TABLE borderColor=#ffcc66 width="90%" align=center bgColor=#e6e4dd border=1>
  <TBODY>
  <TR>
    <TD>gametime=0;<BR>gametimeoffset=System.currentTimeMillis();</TD></TR></TBODY></TABLE><BR>  以后只要游戏不gameover就在每个更新周期都进行一次计算:<BR><BR>
<TABLE borderColor=#ffcc66 width="90%" align=center bgColor=#e6e4dd border=1>
  <TBODY>
  <TR>
    <TD>gametime=(System.currentTimeMillis()-gametimeoffset)/1000;<BR>//转换为秒</TD></TR></TBODY></TABLE><BR>  下面要做的就是将它显示出来,还记得我们曾经实现的字体类了吗,这下子有用了,首先是实例化一个字体类:<BR><BR>
<TABLE borderColor=#ffcc66 width="90%" align=center bgColor=#e6e4dd border=1>
  <TBODY>
  <TR>
    <TD>img=ImageTools.getImage("/pic/b_number.png");<BR>fontbig=new 
      Font(g,img,10,15,<BR>new 
    char[]{'0','1','2','3','4','5','6','7','8','9'});</TD></TR></TBODY></TABLE><BR>  然后就是显示:<BR><BR>
<TABLE borderColor=#ffcc66 width="90%" align=center bgColor=#e6e4dd border=1>
  <TBODY>
  <TR>
    <TD>fontbig.drawString(String.valueOf(gametime),screenwidth/2-15,10);</TD></TR></TBODY></TABLE><BR>  还真是方便yeah!<BR><BR>  接着是奖励系统,我们规定每过20s就加一个bomb给玩家。<BR><BR>
<TABLE borderColor=#ffcc66 width="90%" align=center bgColor=#e6e4dd border=1>
  <TBODY>
  <TR>
    <TD>int 
      awardindex=(int)gametime/20;//计算奖励时间<BR>if(awardindex&gt;bombawardtop)<BR>awardindex=bombawardtop;<BR>if(bombaward[awardindex]!=0){//如果本20s没有奖励<BR>bombnum+=bombaward[awardindex];<BR>bombaward[awardindex]=0;//奖励过了<BR>}</TD></TR></TBODY></TABLE><BR>  尽可能简单和给出些提示是我写本文的原则, 
所以评价系统,很ez。<BR><BR>  我们建立一个辅助类,提供一个方法,输入游戏时间,返回一个String评语。<BR><BR>
<TABLE borderColor=#ffcc66 width="90%" align=center bgColor=#e6e4dd border=1>
  <TBODY>
  <TR>
    <TD>public class StringTools {<BR> protected StringTools() 
      {<BR>}<BR><BR>public static String timeOpinion(long 
      gametime){<BR> if(gametime&lt;10){<BR>  return "Do you play with your 
      foot?";<BR>  //return "i can't belive,your are a game master";<BR> }else 
      if(gametime&lt;16){<BR>  return "come boy, you can do it!";<BR> }else 
      if(gametime&lt;20){<BR>  return "what a pity! try again.";<BR> }else 
      if(gametime&lt;25){<BR>  return "very well, you are a real 
      man.";<BR> }else if(gametime&lt;30){<BR>  return "i know you have talent 
      of this game.";<BR> }else if(gametime&lt;40){<BR>  return "i can't belive, 
      your are a game master.";<BR> }else{<BR>  return "oh my god, are you a 
      human?";<BR> }<BR>}<BR><BR>}</TD></TR></TBODY></TABLE><BR>  之后显示出来就好了,我手头没有合适大小的字体图片,我直接使用<BR><BR>
<TABLE borderColor=#ffcc66 width="90%" align=center bgColor=#e6e4dd border=1>
  <TBODY>
  <TR>
    <TD>g.drawString(StringTools.timeOpinion(gametime),5,22,g.LEFT|g.TOP);</TD></TR></TBODY></TABLE><BR>  想在手机小小的屏幕容下那么东西是挺费劲的,其实这也是我对手机上玩游戏没什么兴趣,不过我对手机网络应用冲满了信心。 
<BR></DIV>
<DIV class=clear1></DIV></DIV><!--结束-->
<DIV class=clear1></DIV>
<DIV class=newleft1>
<DIV class=space2><SPAN id=ad7></SPAN></DIV></DIV><!--文章评论区-->
<SCRIPT language=JavaScript>
<!--
var aid = 1875341;
var channelid = 324;

//-->
</SCRIPT>

<DIV class=newxiangguan>
<DIV class=newxiangguanmenu><A href="http://my.yesky.com/" 
target=_blank>天极社区</A>邀请您:<A class=red-s href="http://blog.yesky.com/" 
target=_blank>写博客</A>&nbsp;<A class=red-s href="http://photo.yesky.com/" 
target=_blank>上传相片</A>&nbsp;<A class=red-s href="http://bbs.yesky.com/" 
target=_blank>论坛聊天</A>&nbsp;<A class=red-s href="http://bbs.yesky.com/" 
target=_blank>订阅电子杂志</A>&nbsp;<A class=red-s 
href="http://www.yeecai.com/mobileant/tjadd/tjload.html" 
target=_blank>彩信蚂蚁</A>&nbsp;<A class=red-s 
href="http://hot.yesky.com/">推荐网摘</A>&nbsp;<A class=red-s 
href="http://training.yesky.com/">IT培训</A>&nbsp;<A class=red-s 
href="javascript:sendemail()" target=_self>对此感兴趣</A>&nbsp;<A 
title="推荐到天极网摘 http://hot.yesky.com [鼠标划选本文摘要,然后点击本图片]" 
href="javascript:d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(yesky=window.open('http://hot.yesky.com/dp.aspx?t='+escape(d.title)+'&amp;u='+escape(d.location.href)+'&amp;c='+escape(t)+'&amp;st=2','yesky','scrollbars=no,width=400,height=480,left=75,top=20,status=no,resizable=yes'));yesky.focus();" 
target=_self><IMG src="J2ME 2D小游戏入门之计时器.files/souchang1.gif" border=0></A> 
</DIV>
<DIV class=newxiangguancontent><SPAN style="FONT-SIZE: 9pt"><B>收藏到:</B><A 
title=天极网摘 
href="javascript:d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(yesky=window.open('http://hot.yesky.com/dp.aspx?t='+escape(d.title)+'&amp;u='+escape(d.location.href)+'&amp;c='+escape(t)+'&amp;st=2','yesky','scrollbars=no,width=400,height=480,left=75,top=20,status=no,resizable=yes'));yesky.focus();" 
target=_self><SPAN style="COLOR: red">天极网摘</SPAN></A> <A 
href="javascript:d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(vivi=window.open('http://vivi.sina.com.cn/collect/icollect.php?pid=wellknow&amp;title='+escape(d.title)+'&amp;url='+escape(d.location.href)+'&amp;desc='+escape(t),'vivi','scrollbars=no,width=480,height=480,left=75,top=20,status=no,resizable=yes'));vivi.focus();" 
target=_self><SPAN style="COLOR: red">新浪VIVI</SPAN></A> <A title=bangchen.com出品 
href="javascript:t=document.title;u=location.href;e=document.selection?(document.selection.type!='None'?document.selection.createRange().text:''):(document.getSelection?document.getSelection():'');void(open('http://bookmark.hexun.com/post.aspx?title='+escape(t)+'&amp;url='+escape(u)+'&amp;excerpt='+escape(e),'HexunBookmark','scrollbars=no,width=600,height=450,left=80,top=80,status=no,resizable=yes'));" 
target=_self><SPAN style="COLOR: red">和讯网摘</SPAN></A> <A title=博彩中心 
href="javascript:d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(boit=window.open('http://blogmark.blogchina.com/jsp/key/quickaddkey.jsp?k='+encodeURI(d.title)+'&amp;u='+encodeURI(d.location.href)+'&amp;c='+encodeURI(t),'boit','scrollbars=no,width=500,height=430,status=no,resizable=yes'));boit.focus();" 
target=_self><SPAN style="COLOR: red">博彩中心</SPAN></A> <A 
href="javascript:d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(keyit=window.open('http://www.365key.com/storeit.aspx?t='+escape(d.title)+'&amp;u='+escape(d.location.href)+'&amp;c='+escape(t),'keyit','scrollbars=no,width=475,height=575,left=75,top=20,status=no,resizable=yes'));keyit.focus();" 
target=_self><SPAN style="COLOR: red">365Key网摘</SPAN></A> <A title=poco网摘 
href="javascript:d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(keyit=window.open('http://my.poco.cn/fav/storeIt.php?t='+escape(d.title)+'&amp;u='+escape(d.location.href)+'&amp;c='+escape(t),'keyit','scrollbars=no,width=475,height=575,left=75,top=20,status=no,resizable=yes'));keyit.focus();" 
target=_self><SPAN style="COLOR: red">poco网摘</SPAN></A> <A title=加入狐摘 
href="javascript:d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(keyit=window.open('http://z.sohu.com/storeit.do?t='+escape(d.title)+'&amp;u='+escape(d.location.href)+'&amp;c='+escape(t),'keyit','scrollbars=no,width=475,height=575,left=75,top=20,status=no,resizable=yes'));keyit.focus();" 
target=_self><SPAN style="COLOR: red">狐摘</SPAN></A> <A 
href="javascript:d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(websnip=window.open('http://x.yeeyoo.com/MouseAdd.aspx?t='+escape(d.title)+'&amp;u='+escape(d.location.href)+'&amp;c='+escape(t),'yeeyoo','scrollbars=no,width=475,height=450,left=280,top=50,status=no,resizable=yes'));websnip.focus();;" 
target=_self><SPAN style="COLOR: red">亿友响享Yeeyoo</SPAN></A> <BR><A 
href="javascript:d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(keyit=window.open('http://www.wzChina.net/collect2.asp?title='+escape(d.title)+'&amp;u='+escape(d.location.href)+'&amp;brief='+escape(t),'keyit','scrollbars=no,width=500,height=520,left=75,top=10,status=no,resizable=yes'));" 
target=_self><FONT colr="#222222">网摘中国</FONT></A> <A title=加加文摘 
href="javascript:d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(jiait=window.open('http://z365.cn/saveZ.aspx?t='+escape(d.title)+'&amp;u='+escape(d.location.href)+'&amp;c='+escape(t),'jiait','scrollbars=no,width=475,height=575,left=75,top=20,status=no,resizable=yes'));jiait.focus();" 
target=_self>加加文摘</A> <A 
href="javascript:u=location.href;t=document.title;void(open('http://www.igooi.com/addnewitem.aspx?noui=yes&amp;jump=close&amp;url='+escape(u)+'&amp;title='+escape(t)+'&amp;sel='+escape(document.selection.createRange().text),'igooi', 'toolbar=no,width=400,height=480'));" 
target=_self>igooi-it网摘</A> <A title=5seek网摘 
href="javascript:d=document;if%20(!sel)%20{var%20sel%20=%20'';};char%20=d.charset;title=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(keyit=window.open('http://www.5seek.com/storeit.asp?title='+escape(d.title)+'&amp;url='+escape(d.location.href)+'&amp;char='+escape(d.char)+'&amp;sel='+escape(d.sel),'keyit','scrollbars=no,width=515,height=555,left=75,top=20,status=yes,resizable=yes'));keyit.focus();" 
target=_self>5seek网摘</A> <A title=36963网摘 
href="javascript:d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(keyit=window.open('http://www.i2key.com/StoreIt.aspx?t='+escape(d.title)+'&amp;u='+escape(d.location.href)+'&amp;c='+escape(t),'keyit','scrollbars=no,width=475,height=475,left=75,top=20,status=no,resizable=yes'));keyit.focus();" 
target=_self>I2Key</A> <A title=帮衬国际出品 
href="javascript:d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(wozhai=window.open('http://www.wozhai.com/wozhai/Cento.asp#t='+escape(d.title)+'&amp;u='+escape(d.location.href)+'&amp;c='+escape(t),'wozhai','scrollbars=no,width=475,height=575,left=75,top=20,status=no,resizable=yes'));wozhai.focus();" 
target=_self>我摘网摘</A> <A title=天下图摘(www.cn3.cn) 
href="javascript:d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(keyit=window.open('http://www.cn3.cn/user/addurl.asp?t='+escape(d.title)+'&amp;u='+escape(d.location.href)+'&amp;c='+escape(t),'keyit','scrollbars=no,width=490,height=450,left=120,top=50,status=no,resizable=yes'));keyit.focus();" 
target=_self><FONT color=#cc0000>天下图摘</FONT></A> <A title=YouNote 
href="javascript:d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(youit=window.open('http://www.younote.com/Noteit.aspx?t='+escape(d.title)+'&amp;u='+escape(d.location.href)+'&amp;c='+escape(t),'youit','scrollbars=no,width=475,height=575,status=no,resizable=yes'));youit.focus();" 
target=_self>YouNote</A> <A title=百特门 
href="javascript:d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange ().text:''):(d.getSelection?d.getSelection():'');void(vkey=window.open('http://www.bytemen.net/vkey/AddText.aspx?site=2005&amp;t='+escape(d.title)+'&amp;u='+escape(d.location.href)+'&amp;c='+escape(t),'vkey','scrollbars=no,width=475,height=575,left=75,top=20,status=no,resizable=yes'));vkey.focus();" 
target=_self>百特门</A> </SPAN><BR></DIV></DIV>
<DIV class=clear1></DIV>
<DIV class=pinlunbox>
<DIV class=pinlunguan3><SPAN id=commentsSpanText>
<SCRIPT language=JavaScript><!--function getTagId(tName) {	tName = tName.replace(/(^[\s ]*)|([\s ]*$)/g, "");	var tagid = 0;	for(var ti = 0; ti < tName.length; ti++) {		tagid += tName.charCodeAt(ti);	}	return tagid;}function UrlEncode(str){   var i,temp,p,q;   var result="";   str = str.replace(/(^[\s ]*)|([\s ]*$)/g, "");   for(i=0;i<str.length;i++){      temp = str.charCodeAt(i);      if(temp>=0x4e00){         execScript("ascCode=hex(asc(\""+str.charAt(i)+"\"))", "vbscript");         result+=ascCode.replace(/(.{2})/g, "%$1");      }else{         result+=escape(str.charAt(i));      }   }   return result;}if(typeof(channelid) == "undefined") channelid = 0;if(typeof(aid) != "undefined") {	if(typeof(tagname) == "string" && tagname.length > 0) {		document.write(" <a href=\"http://comments.yesky.com/t/"+UrlEncode(tagname)+"/6," + channelid + "/" + aid + ".shtml\" class=\"red-s\"  target=\"_blank\">查看主题:<font color=\"#FF0000\">" + tagname + "</font>的内容</a>");	} else {		document.write(" <a href=\"http://comments.yesky.com/a/6," + channelid + "/" + aid + ".shtml\" class=\"red-s\"  target=\"_blank\">查看所有内容</a>");	}}//--></SCRIPT>
</SPAN>
<SCRIPT language=JavaScript>function showCommentsSpan() {	if(typeof(latest_comments_poster) == "object" && latest_comments_poster.length && latest_comments_poster.length > 0) {		var re = /(\[s(\d{1,2})\])/ig;		var str = "<div class=\"wzplcontent\">";		str += "本文最新主题 共(<span class=\"fontcolor\">"+ latest_comments_num +"</span>)条";		if(typeof(tagname) == "string" && tagname.length > 0) {			str += " &gt;&gt; &gt;&gt; &gt;&gt;  <a href=\"http://comments.yesky.com/t/" + UrlEncode(tagname) + "/6," + channelid + "/" + aid + ".shtml\" target=\"_blank\" class=\"red-s\"><b>查看主题:</b><font color=\"#FF0000\">" + tagname + "</font>所有主题</a> &lt;&lt; &lt;&lt; &lt;&lt; ";		} else {			str += " &gt;&gt; &gt;&gt; &gt;&gt; <a href=\"http://comments.yesky.com/a/6," + channelid + "/" + aid + ".shtml\" target=\"_blank\" class=\"red-s\">查看该文章所有相关主题</a> &lt;&lt; &lt;&lt; &lt;&lt; ";		}		str += "</div>";		var hasVisits = typeof(latest_comments_visits) == "object" && latest_comments_visits.length > 0;		 var hasTag = typeof(latest_comments_tagid) == "number" && latest_comments_tagid > 0;		if(hasVisits) {			str += "<table width=\"99%\" border=\"1\" cellspacing=\"0\" cellpadding=\"2\" align=\"center\" style=\"line-height: 120%\" bordercolor=\"#FFFFFF\" bordercolorlight=\"#D0CCD0\">"	+"\n"+			" <tr bgcolor=\"#FFFFFF\">"	+"\n"+			"    <td width=\"7%\">点击</td>"	+"\n"+			"    <td width=\"7%\">回贴</td>"	+"\n"+			"    <td width=\"50%\">标题</td>"	+"\n"+			"    <td width=\"15%\">发表时间</td>"	+"\n"+			"    <td width=\"21%\">发表人</td>"	+"\n"+			"</tr>"	;			for (i = 0; i < latest_comments_poster.length && i < 10; i++) {				str += "<tr bgcolor=\"#F6F6F6\">"	+"\n"+				"	<td>" + latest_comments_visits[i] + "</td>"	+"\n"+				"	<td>" + latest_comments_replies[i] + "</td>";				var url;				if (hasTag) {					url = "http://comments.yesky.com/l/" + latest_comments_id[i] + "/" + latest_comments_tagid + "/" + latest_comments_type[i] + "," + channelid + "/" + latest_comments_rfid[i] + ".shtml"				} else {					url = "http://comments.yesky.com/l/" + latest_comments_id[i] + "/" + 0 + "/" + latest_comments_type[i] + "," + channelid + "/" + latest_comments_rfid[i] + ".shtml"				}				str += "	<td><a href=\"" + url + "\" target=\"_blank\">" + latest_comments_contents[i].replace(re,"<img src=/TLimages/smile/face$2.gif border=0 align=middle> ") + "</a></td>"	+"\n"+				"	<td><font color=\"#CC6600\">" + latest_comments_postdate[i] + "</font></td>"	+"\n"+				"	<td nowrap=\"\" ><font color=\"#FF3300\">" + latest_comments_poster[i] + "</font></td>"	+"\n"+				"</tr> ";			}			str += "</table>";		} else {			var hasLevel = typeof(latest_comments_level) == "object";			str += "<div class=\"wzplcontent\">";			str += "<ul class=\"spaceListul\">";			for (i = 0; i < latest_comments_poster.length && i < 10; i++) {				if(hasLevel) {					str += "[" + latest_comments_level[i] + "楼:<span class=\"fontcolor\">";				} else {					str += "[ <span class=\"fontcolor\">";				}				str += latest_comments_poster[i];				str += "</span>]  ";				str += latest_comments_contents[i].replace(re,"<img src=/TLimages/smile/face$2.gif border=0 align=middle> ");				str += "  (";				str += latest_comments_postdate[i];				str += "  )<br/>";			}			str += "</ul></div>";		}		commentsSpanText.innerHTML = str;	} else {		var str = "<div>";		str += "目前本文还没有相关主题。立即发表主题,马上成为本文的第一个发表者!";		str += "</div>";		commentsSpanText.innerHTML = str;	}}</SCRIPT>

<SCRIPT language=JavaScript><!--if(typeof(aid) != "undefined") {	if(typeof(tagname) == "string" && tagname.length > 0) {		document.write("<script language=\"JavaScript\" charset=\"gb2312\"  src=\"http://comments.yesky.com/tagview/"+(getTagId(tagname)%5000)+"/"+getTagId(tagname)+".js\"><\/script>");	} else {		document.write("<script language=\"JavaScript\" charset=\"gb2312\"  src=\"http://comments.yesky.com/articlereview/6/"+(aid%5000)+"/"+aid+".js\"><\/script>");	} }//--></SCRIPT>
</DIV>
<DIV class=pinlunguan3>
<DIV class=pinlunguan1>
<SCRIPT src="J2ME 2D小游戏入门之计时器.files/uc.js" type=""></SCRIPT>
发表主题:(Html:禁止,UBB:允许) 
<FORM name=frmReviewPost action=http://comments.yesky.com/review.post.do 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -