基于j2me的推箱子游戏毕业设计论文任务书(编辑修改稿)内容摘要:

循环标记位 int sleepSpan = 300。 //睡眠的毫秒数 PushBoxActivity pushBoxActivity。 public MenuViewGoThread(PushBoxActivity pushBoxActivity){ = pushBoxActivity。 } public void run(){ while(flag){ if( != null){ if( 320){//当移动过远时将坐标重置到 0 = 0。 } = 2。 //每次循环向左移两个单位 try{ (sleepSpan)。 //睡眠 } catch(Exception e){ ()。 } } } } } 19 图三 欢迎界面图 图四 菜单界面图 三. 游戏界面 设计 在游戏界面设计中首先要使 菜单界面 MenuView 类 实现。 代码如下: package。 import。 import。 import。 import。 import。 import。 import。 public class MenuView extends SurfaceView implements { PushBoxActivity pushBoxActivity。 //主 Activity 的引用 MenuViewDrawThread menuViewDrawThread。 20 Paint paint。 //画笔 Bitmap start1。 //开始游戏图片 Bitmap sound1。 //声音图片 Bitmap sound2。 Bitmap help1。 //游戏说明图片 Bitmap exit1。 //退出游戏图片 Bitmap menubackground。 //大背景图片 Bitmap menubackground2。 //小背景图片 int menubackgroudX = 0。 //需要移动的背景的坐标 public MenuView(PushBoxActivity pushBoxActivity) {//构造器 super(pushBoxActivity)。 = pushBoxActivity。 menuViewDrawThread = new MenuViewDrawThread(this, getHolder())。 getHolder().addCallback(this)。 paint = new Paint()。 start1 = (getResources(), )。 //初始化开始 sound1 = (getResources(), )。 //初始化打开声音 sound2 = (getResources(), )。 //初始化关闭声音 help1 = (getResources(), )。 //初始化帮助 exit1 = (getResources(), )。 //初始化退出 menubackground = (getResources(), )。 menubackground2 = (getResources(), )。 } protected void onDraw(Canvas canvas) { (canvas)。 (menubackground, menubackgroudX, 0, paint)。 //绘制大背景 (menubackground2, 21, 20, paint)。 //绘制小背景 21 (start1, 60, 60, paint)。 if(){//根据声音的状态绘制声音按钮图片 (sound1, 60, 150, paint)。 } else{ (sound2, 60, 150, paint)。 } (help1, 60, 240, paint)。 //绘制帮助 (exit1, 60, 330, paint)。 //绘制退出按钮 } public boolean onTouchEvent(MotionEvent event) { if(()50 amp。 amp。 () 50+() amp。 amp。 ()60 amp。 amp。 ()60+()){//点击了开始游戏菜单 if(()){ ()。 } (2)。 //向 Activity的 Handler 发送消息 } else if(()50 amp。 amp。 ()50+() amp。 amp。 ()70+() amp。 amp。 ()70+()+()){ //点击了声音菜单 = !。 //将声音开关取反 if(!){ if(()){ ()。 //停止播放声音 } if(()){ ()。 //停止播放声音 } 22 } else{ if(!()){ ()。 //开始播放声音 } } } else if(()50 amp。 amp。 ()50+() amp。 amp。 ()80+()+() amp。 amp。 ()80+()+()+()){ //点击的是游戏说明菜单 } else if(()50 amp。 amp。 ()50+() amp。 amp。 ()90+()+()+() amp。 amp。 ()90+()+()+()+()){ //点击的是退出游戏菜单 (0)。 //退出游戏 } return (event)。 } public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { } public void surfaceCreated(SurfaceHolder holder) { (true)。 ()。 } public void surfaceDestroyed(SurfaceHolder holder) { boolean retry = true。 (false)。 //停止刷帧线程 23 while (retry) { try { ()。 //等待刷帧线程结束 retry = false。 } catch (InterruptedException e) {//不断地循环,直到等待的线程结束 } } } } 基本界面搭建完成,然后绘制线程 MenuViewDrawThread 对菜单界面进行刷帧操作。 MenuViewDrawThread 类的实现方法同 WeleViewDrawThread 的完全相同。 如果希望界面的背景滚动起来,则还需要开发 MenuViewDrawThread 线程类,在该线程类的 run 方法中循环改变 MenuView 中背景图片的坐标即可。 四. 游戏界面框架设计 游戏最主要的环节 游戏界面的开发,下面是对游戏界面的整体框架进行简单介绍。 游戏 界 面设计 基本框架图: 图三 游戏界面设计基本框架图 24 ( 5) GameView 框架的实现。 代码如下: package。 import。 import。 import。 import。 import。 import。 import。 import。 import。 public class GameView extends SurfaceView implements { PushBoxActivity pushBoxActivity。 GameViewDrawThread gameViewDrawThread。 int initX = 70。 //绘制时第一个的坐标 ,即开始绘制的位置 int initY = 50。 Paint paint。 Bitmap greenBox。 //绿色的箱子 Bitmap wall。 //墙 Bitmap box。 //箱子 Bitmap exit2。 //退出按钮图片 Bitmap goon。 //恭喜过关的图片 int tx = 1。 int ty = 1。 //当前移动箱子的坐标 ,1 表示没有移动的 int tempi = 0。 //当前移动箱子的 i int tempj = 0。 //当前移动箱子的 j int status = 0。 //0 正常游戏中 ,1 胜利 public GameView(PushBoxActivity pushBoxActivity) {//构造器 super(pushBoxActivity)。 25 = pushBoxActivity。 gameViewDrawThread = new GameViewDrawThread(this,getHolder())。 getHolder().addCallback(this)。 initBitmap()。 } public void initBitmap(){ paint = new Paint()。 greenBox = (getResources(), )。 //绿色的箱子 wall = (getResources(), )。 //墙 box = (getResources(), )。 //箱子 exit2 = (getResources(), )。 //墙 goon = (getResources(), )。 } protected void onDraw(Canvas canvas) { if(status == 0){//正常游戏中 (true)。 //抗锯齿 ()。 //绘制黑背景 //绘制第一层 ,即地板层 for(int i=0。 i。 i++){ for(int j=0。 j[i].length。 j++){ //根据索引值进行坐 标转换 int X = initX+36*j15*i。 int Y = initY+10*j+25*i。 if([i][j] == 0){//白色空地 ((255, 220, 220, 220))。 (canvas, X, Y)。 } else if([i][j] == 1){//灰色空地 ((255, 170, 170, 170))。 (canvas, X, Y)。 26 } else if([i][j] == 2){//目的地 1 ((255, 127, 255, 130))。 (canvas, X, Y)。 } else if([i][j] == 3){//目的地 2 ((255, 60, 255, 120))。
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。 用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。