j2me手机拼图游戏毕业论文(编辑修改稿)内容摘要:

Command(暂停计时 , , 1))。 } if(().equals(4*4记时记步 拼图 )){ //选择 4*4记时记步拼图 p_name=(())。 MyCanvas mc=new MyCanvas(dis,temp,4,4)。 zhuanh()。 (/+p_name)。 ()。 ()。 广东海洋大学寸金学院 20xx 届毕业论文 (设计 ) 9 (mc)。 //转到画布界面 (new Command(返回 , , 1))。 (new Command(暂停计时 , , 1))。 } } } 该类中使用了 3个方法,下面分别介绍这 3个方法: startApp()方法 : 当 MIDlet 运 行时, startApp 函数自动调用,应用程序进入运行(Active)状态,此时程序正在运行中, 将 列表框 l 设置为当前界面。 并将 l 上的Command 按钮和事件处理类 (CommandListener)对象绑定。 showList()方法:该方法完善列表框 (如图 3_1),实现了刚进入游戏时的选择界面 ,并在 l 界面添加 3 个软键按键“普通拼图 ” 、“ 3*3 记时记步 拼图 ” 、 “ 4*4 记时记步 拼图 ” 按钮。 mandAction()方法: mandAction()方法为实现 CommandListener 接口后必须 重写的方法。 实现对 l 界面选择“普通拼图”、“ 3*3 记时记步 拼图”、“ 4*4 记时记步 拼图” 3 个软键按键的方法响应。 默认选择草莓图片,按右软键后: 选择“普通拼图”后按选择键,实例化 MyCanvas 类的对象 mc (传参dis,temp,3,4),并实现 mc 的方法,转到画布界面,在画布界面添加“返回”软键按键(界面如图 3_2); 选择“ 3*3 记时记步 拼图”后按选择键,实例化 MyCanvas 类的对象 mc(传参dis,temp,3,3),并实现对象 mc 的方法,转到画布界面,在画布界面添加“返回”和“暂停计时 ”软键按键 (界面如图 3_3); 选择“ 4*4 记时记步 拼图 ” 后按选择键,实例化 MyCanvas 类的对象 mc(传参dis,temp,4,4),并实现对象 mc 的方法,转到画布界面,在画布界面添加“返回”和“暂停计时”软键按键 (界面如图 3_4)。 广东海洋大学寸金学院 20xx 届毕业论文 (设计 ) 10 图 3_1 列表框界面图 图 3_2 普通拼图界面图 图 3_3 3*3 记时记步拼图界面图 图 3_4 4*4 记时记步拼图界面图 广东海洋大学寸金学院 20xx 届毕业论文 (设计 ) 11 MyImage 类 定义了 MyImage 类来表示分割后的小图块,其主要代码如下 : package PinTu。 import。 public class MyImage { private Image image=null。 private int old_x=0。 private int old_y=0。 private int x=0。 private int y=0。 public MyImage(Image image, int old_x, int old_y) { super()。 = image。 = old_x。 = old_y。 =old_x。 =old_y。 } public int getX() { return x。 } public void setX(int x) { = x。 } public int getY() { return y。 } public void setY(int y) { = y。 广东海洋大学寸金学院 20xx 届毕业论文 (设计 ) 12 } public Image getImage() { return image。 } public int getOld_x() { return old_x。 } public int getOld_y() { return old_y。 } public boolean check(){ if(old_x==xamp。 amp。 old_y==y){ return true。 } return false。 } } 该类 3 个参数, image 用来表示小图块, old_x 与 ole_y 表示小图块起始坐标。 同时用 2 个变量 x 和 y 来改变小图块的坐标,初始值分别等于 old_x 与 ole_y。 包含的方法分别实现:得到 x; 修改 x; 得到 y; 修改 y; 得到表示小方块的参数;得到该小方块的初始坐标 old_x。 得到该小方块的初始坐标 old_y。 最后的 check()方法是判断小图块改变后的坐标 x 与 y 是否与初始坐标 old_x 与ole_y 相等,是的话返回 true,不是返回 false。 MyCanvas 类 MyCanvas 类继承自 Canvas,实现 CommandListener 与 Runnable 接口。 主要代码如下 : package PinTu。 import。 import。 广东海洋大学寸金学院 20xx 届毕业论文 (设计 ) 13 import。 import。 import。 import。 import。 import。 import。 import。 import。 import。 import。 public class MyCanvas extends Canvas implements CommandListener , Runnable { private Image image=null。 private int xuanz_x。 private int xuanz_y。 private MyImage is[][]。 private MyImage Nimage=null。 public int null_x。 public int null_y。 private boolean game_key=false。 private boolean game_miji。 private Display d=null。 private List l=null。 private String miji=。 private String miji_temp=。 private int jishu。 private int jishi。 private int shuz。 public boolean bRUN。 //构造函数 广东海洋大学寸金学院 20xx 届毕业论文 (设计 ) 14 public MyCanvas(Display d, List l, int xuanz_x, int xuanz_y) { super()。 game_miji=true。 = d。 = l。 =xuanz_x。 =xuanz_y。 null_x=xuanz_x1。 null_y=xuanz_y1。 is=new MyImage[xuanz_x][xuanz_y]。 jishu=0。 jishi=0。 (this)。 bRUN=true。 Thread th=new Thread(this)。 ()。 } //画布函数 protected void paint(Graphics arg0) { (255, 255, 255)。 (0, 0, (), ())。 for(int i=0。 ixuanz_x。 i++) { for(int j=0。 jxuanz_y。 j++) {if(is[i][j]!=null) (is [i][j].getImage(), is[i][j].getX(), is[i][j].getY(), 0)。 else {if(xuanz_x==3amp。 amp。 xuanz_y==4) (null_x*80, null_y*80, 75, 75)。 if(xuanz_x==3amp。 amp。 xuanz_y==3) 广东海洋大学寸金学院 20xx 届毕业论文 (设计 ) 15 (null_x*80, null_y*80, 75, 75)。 if(xuanz_x==4amp。 amp。 xuanz_y==4) (null_x*60, null_y*60, 55, 55)。 } } } if(game_key) {if(xuanz_x==3amp。 amp。 xuanz_y==4) (image, 0, 0, 0)。 if((xuanz_x==3amp。 amp。 xuanz_y==3)||(xuanz_x==4amp。 amp。 xuanz_y==4)) (image, 0,()240, 240, 240, , 0, 0,|)。 } if((xuanz_x==3amp。 amp。 xuanz_y==3)||(xuanz_x==4amp。 amp。 xuanz_y==4)) {(0, 0, 0)。 Font font = (,|,Fon)。 (font)。 (时间 +:+ +(jishi)+(秒 )+ + 移动次数 + +:+ +(jishu), ()20, ()10, |)。 if(jishu==9999||jishi==9999) {Form fom=new Form(别浪费时间了 )。 (fom)。 //所用时间太长 移动次数太多 自动跳转 (this)。 (new Command(返回 , , 1))。 } } } //加入图片 public void addImage(String p_name){ 广东海洋大学寸金学院 20xx 届毕业论文 (设计 ) 16 try { image=(p_name+.gif)。 } catch (IOException e) {()。 } } //分割图片 public void allimag。
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。 用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。