




免费预览已结束,剩余28页可下载查看
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
本 科 毕 业 设 计 设 计 题 目 基于j2me手机拼图游戏的关键技术研究与实现 姓名(学号) 系 别 专 业 通信工程 导 师 姓 名 基于j2me的手机拼图游戏的关键技术研究与实现作 者指导教师摘要: 在21世纪的信息时代,随着通信技术的高速发展,移动网络终端性能的不断提高与完善以及手机的高普及率,人们对手机终端应用开发的需求在不断增大,其对手机的需求已不仅仅是把作为一款简单的通讯工具,而是渐渐习惯于手机作为新的娱乐工具,因而手机越来越多的应用到人们的生活中,特别是手机游戏的推出受到了人们热烈的追捧,而我所设计的这款手机拼图游戏对于人们的智力开发有一定的帮助。在拼图游戏中用到的关键技术主要有手机游戏的图像和按键处理、多线程的使用等关键技术及解决方案。在手机游戏图像处理这一块用了canvas类的子类gamecanvas进行游戏画布,通过算法计算图形界面的尺寸。在按键事件处理方面也是通过canvas类中的三个方法进行设置,包括按键按下的时候,按键长按的时候以及按键释放的时候。为了使玩家一边玩游戏的同时可以听到动感的声音,所以在这个拼图游戏中使用了多线程,由于多个线程之间可能会共享内存,而多线程的机制实际上相当于cpu交替分配给不同的代码段来运行,因此安全问题就成了重要问题。在这一方面也做了安全处理,在代码中增加了关键字synchronized ,使线程同步,如果其他线程要想调用这个资源就需要等待,保证了机制的安全运行。在异常方面,抛出的各种各样异常也做了相应的处理。经过以上技术处理基本解决了手机拼图游戏的运行及安全工作。关键词:j2me插件;拼图;手机游戏。jigsaw puzzle based on the j2me mobile phone key technology research abstract:with the rapid development of communications technology in the 21st century information age, the high penetration of mobile network terminal continuously improve the performance and improvement, as well as mobile phones, the demand for application development of mobile terminals in increasing demand for mobile phonesnot just as a simple communication tool, but gradually accustomed to the phone as a new entertainment tool, and thus the phone more and more to peoples lives, especially the introduction of mobile games has been the enthusiastic pursuiti designed this phone jigsaw puzzle with the help of peoples intellectual development.the key techniques used in the jigsaw puzzle mobile games, images and buttons, multi-threaded use of key technologies and solutions. this one with a subclass of the canvas class gamecanvas game canvas, by the algorithm to calculate the size of the graphical interface in the mobile game image processing. three methods in the canvas class in the button event handler is set when the button is pressed, the button a long time, as well as the button is released. in order to make the players while playing the game while you can hear the voice of the dynamic multi-threaded, so in this jigsaw puzzle, may share memory between multiple threads, multi-threading mechanism is actually equivalent to the cpu alternately assigned to different section of code to run, security has become an important issue. safe handling, in this keyword the synchronized code, so that the thread synchronization, if the other threads in order to call this resource need to wait, to ensure the safe operation of the mechanism. in the unusual aspects of a variety of abnormalities were also thrown the appropriate treatment. after basically solve the above technical processing of the operation and safety of the phone puzzle.key words:j2me plug-ins; puzzle; mobile games. 目录1 引言.11 .1开发研究背景及意义.1 1.1.1 开发的目的和意义.1 1.1.2 该课题领域的开发及应用现状分析.2 2 需求分析.2 2.1 系统描述.2 2.1.1本游戏的设计规则.2 2.1.2游戏实现通过位置的计算.3 2.2 运行环境.4 2.2.1 j2me体系结构介绍.4 2.2.2 jdk的安装及作用.5 2.2.3 wireless toolkit 2.4.2的安装及配置.6 2.2.4 eclipse,eclipse me整合wtk.73 系统原理.8 3.1 系统原理分析.8 3.2 系统原理功能分析.9 3.3 系统原理用例图.10 3.4 系统原理图. .11 4 详细设计.12 4.1 系统模块操作.12 4.1.1 图片分割模块. .13 4.1.2图片分割后重组模块.14 4.1.3键盘控制图片移动模块.16 4.1.4 辅助模块.18 4.1.5结果分析模块.20 4.2用户操作模块.22 5 系统测试.26 总 结.33致 谢.33 附件:参考文献1 引言1.1 开发研究背景及意义 1.1.1 开发的目的和意义实现j2me手机拼图游戏的关键技术;随着智能手机的逐步普及,手机游戏也日益流行起来。利用j2me手机应用平台,利用j2me的移动开发midp架构,设计和开发了一款拼图游戏。在游戏中融入了图片拆分和分散技术,并在游戏当中使用了多线程,以提高游戏的趣味性,由于java语言能够实现具备复杂的逻辑和功能的手机游戏,大量已有的java游戏程序将被应用到手机上或者手机应用互动,因此,在当前j2me手机游戏有着巨大的市场机遇和商业价值的背景下,在j2me手机游戏技术比较成熟的背景下,加强j2me手机游戏的开发是必须的。 1.1.2 该课题领域的开发及应用现状分析 在21世纪的信息时代,随着通信技术的高速发展,移动网络终端性能的不断提高与完善以及手机的高普及率,人们对手机终端应用开发的需求在不断增大,其对手机的需求已不仅仅是把作为一款简单的通讯工具,而是渐渐习惯于手机作为新的娱乐工具,因而智能手机越来越多的应用到人们的生活中,特别是手机游戏的推出受到了人们热烈的追捧,而我所设计的这款手机拼图游戏对于人们的智力开发有一定的帮助。所以这个课题的研究在如今社会具有一定应用价值。2 需求分析2.1系统描述 2.1.1 本游戏的游戏设计规则 首先进入手机主菜单界面,然后进入游戏菜单界面选择游戏难度,进入拼图游戏后,出现4个方格、16个方格或是64个方格的游戏界面上有一个空格,通过按手机的4个方向键可以将空格对应的上、下、左、右方向的小图块移动到空格中,当所有的小图块被移到了正确的位置后系统会自动显示整个原始图片,这就说明拼图已经完成。在拼图过程中按下手机的选择键可以显示原图,用来进行参照,再按一下后又会回到原来的拼图状态。拼图完成后,进入下一关。本游戏分为3种难度等级,一种为容易等级,是2*2的4个格子的拼图;一种为一般等级,是4x4的16个格子的拼图,一种为困难等级,是8*8的64个格子的拼图。 2.1.2 游戏实现通过位置的计算从大的图片里提取出所需要显示的那部分显示出来,看起来就像是一个小的图块。 利用j2me 的graphics对象方法set clip(int x,int y,int width,int height)方法来实现,先把绘制小图块的区域设置set clip,再绘制大图片,这样只有set clip的区域能被显示出来,看起来的效果就像是一个小图块。小图块的滑动就是变化set clip区域,再调整绘制大图片的起始坐标来实现的。2.2 运行环境2.2.1 java me体系结构介绍 java me可以支持的开发分为两个系列: cdc:互联设备配置(connected device configuration),面向强大的可以间歇式的与网络连接的设备(有稳定的电源供应,设备性能强劲),如:机顶盒、internet电视、家用电器和汽车导航系统等; cldc:互联受限设备配置(connected limited device configuration),主要面对大量的微型设备和嵌入式设备。移动开发(特别是手机移动开发),一般情况下,属于cldc。java me的基本体系结构: 可选包 描述( midp ) 配置(cldc) java运行环境(kvm) 操作系统 2.2.2 jdk的安装及作用 在pc机上利用模拟器进行移动应用开发时,为方便起见,我们将会利用到java移动开发工具包(wtk)、eclipse以及相应插件(eclipse me)。这些软件的运行,都需要有java se的支持。所以,需要进行java se开发环境(jdk)的安装,方便以后开发的进行。 jdk安装完毕之后,在c:program filesjavajdk1.6.0_01下可以找到安装的目录,如图所示: jdk安装目录中,比较重要的文件夹或文件的内容详见下表所示。2.2.3 wireless toolkit 2.4.2的安装及配置 java se的安装只是提供了一个开发环境的支持,为了在pc机上进行移动应用开发,还必须安装无线开发工具包(wireless toolkit, wtk)。所以,本节需要进行wtk的安装,为移动应用开发提供基础支持。安装完毕之后,在c:wtk2.5.2下可以找到安装的目录,如图所示: wtk安装目录中,几个重要的文件夹内容详见表所示:2.2.4 eclipse,eclipse me整合wtk jdk和wtk的安装,提供了一个支持的开发环境,此时可以通过文本编辑器编写移动应用。但是,真实的项目开发中,为了提高开发效率,需要采用一些简便快捷的ide进行支持,目前最流行的ide是eclipse,同时它也是免费的;所以本游戏采用eclipse进行代码编译。eclipse下的java开发,需要利用jdk来进行支持,首先需要将eclipse和jdk进行绑定。打开eclipse,选择“window”“preferences”,得到如图的界面。选择“java”“installed jres”,可以看到eclipse已经和jdk1.6绑定,也可以点击右边的“edit”按钮改变jdk绑定。 eclipse的安装,只能让我们很方便地编写java程序,但是要方便地编写java me程序,并对java me移动应用提供运行模拟,还必须对eclipse的功能进行加强。首先,打开eclipse,选择“window”“preference”,如果eclipse me正常安装,将有一个“j2me”的选项,选择“j2medevice management”。wtk的选择,点击“import”。点击“browse”,选择wtk的安装目录(c:wtk2.5.2),点击“refresh”,就可将wtk中的模拟设备导入。点击“finish”。选择这个模拟器,点击“ok”,完成。3 系统原理 3.1 系统原理分析本系统主界面由智能拼图游戏菜单构成,在主界面主菜单中有三个子菜单,分别是新游戏,游戏排行,游戏说明。(1) 系统主菜单模块:游戏拼图模块是指玩家想要玩该游戏的时候,首先进入的是这个界面,然后进行游戏选择,包括:游戏的等级,查看排行,以及游戏的说明。(2) 系统子菜单模块: 新游戏模块是指玩家进入该模块后进行游戏的难度选择,该模块的难度等级分为简单、一般、困难。前面二个等级比较简单,不需要花费太多的时间就可以完成,但是困难等级相对麻烦一些,不仅要花费大量的的时间,还需要你有高智商的头脑去思考,观察每一个细节。 游戏排行模块是指玩家在闯关后留下的记录,该模块共记录三个级别难度,分别是简单、一般、困难。当玩家选择简单时,闯关过后就会在简单后面记录下该玩家一共闯过多少关,如果一关没有闯过就不会有任何记录。 游戏说明模块是指玩家在玩游戏之前可能会看的一个环节,该模块主要介绍这款游戏的功能以及用途,还有等级的细节说明。3.2 系统原理功能分析 本系统原理的功能是通过人机交互进行游戏操作,利用键盘方向键的控制进行走动。运用线程进行游戏的安全运行。游戏的线程主要由三个部分组成:检测键盘输入(与玩家交互),更新游戏场景(处理游戏逻辑),绘制游戏画布。三个模块相互联系又互相联系,按照模块的思想来实现游戏线程将更加面向对象和便于理解。如果程序运行快于预期速度会使玩家感觉到抖动,从而影响游戏效果,因此还需要检测每帧的运行时间,如果过快则等待一段时间,如果过慢则挂起当前线程允许其他线程执行。3.3 系统原理图 关闭主菜单 返回 游戏主菜单 返回返回 返回确定确定确定 游戏说明游戏排行新游戏 返回确定返回确定返回确定确定确定返回返回确定返回返回确定主要介绍游戏的功能和等级说明。一般困难:第?关简单:第?关一般:第?关困难简单开始游戏开始游戏开始游戏8*8拼图4*4拼图2*2拼图退出退出退出游戏主菜单返回关闭主菜单1.1如图所示为系统原理图 4 详细设计 4.1 系统模块操作 4.1.1 图片分割模块 给图片每一小块分一个编号用二维数组结合在一起,可以定义为整形或者字符串,如4*4:intmap = 00,01,02,03, 10,11,12,13, 20,21,22,23, 30,31,32,33; 程序代码: int edge = 图片宽度/4; public void paint(graphics g)for (int x = 0; x 4; x+) for (int y = 0; y 4; y+) if (mapxy != 33) / 获取编号的第一位数int xsegment = mapxy / 10;/ 获取编号的第二位数int ysegment = mapxy % 10;/ 获取图片中左上角坐标为(xsegment*edge, ysegment*edge)/ 宽度为edge,高度为edge的小块/ 画到界面上左上角坐标为(x*edge, y*edge)的位置g.drawregion(img, xsegment * edge, ysegment * edge, edge,edge, sprite.trans_none, x * edge, y * edge,graphics.left | graphics.top);4.1.2图片分割后打乱重组模块 通过在数组map中任取二个元素交换位置,交换足够多的次数,数组map中的元素就足够乱了,然后根据元素在图片中取土小块,画到界面上。代码如下:void initmap() random rnd = new random();int temp, x1, y1, x2, y2;/ 将地图数组打乱for (int i = 0; i 100; i+) x1 = rnd.nextint(4);x2 = rnd.nextint(4);y1 = rnd.nextint(4);y2 = rnd.nextint(4);temp = mapx1y1;mapx1y1 = mapx2y2;mapx2y2 = temp;this.repaint(); 4.1.3键盘控制图片移动模块 通过设置键盘的方向键,利用方向键进行图片的移动进行拼图程序代码:protected void keypressed(int keycode) int action = this.getgameaction(keycode);int xof33 = -1, yof33 = -1;for (int x = 0; x 4; x+) for (int y = 0; y 4; y+) if (mapxy = 33) xof33 = x;yof33 = y;break;switch (action) case gamecanvas.up:if (yof33 != 3) this.swap(xof33, yof33, xof33, yof33 + 1);break;case gamecanvas.down:if (yof33 != 0) this.swap(xof33, yof33, xof33, yof33 - 1);break;case gamecanvas.left:if (xof33 != 3) this.swap(xof33, yof33, xof33 + 1, yof33);break;case gamecanvas.right:if (xof33 != 0) this.swap(xof33, yof33, xof33 - 1, yof33);break;this.repaint(); public void swap(int xof33, int yof33, int targetx, int targety) int temp = maptargetxtargety;maptargetxtargety = 33;mapxof33yof33 = temp;4.1.4 主界面菜单模块 主界面菜单代码显示如下:public class menulist extends list public static command comdconfirm = new command(确定,command.screen,2);public static command comdback = new command(返回,command.back,1);public static int select_newgame = 0; public static int select_pacein =1; public static int select_desc = 2; private static string title = 智能拼图游戏;public menulist()super(menulist.title,choice.implicit); this.addcommand(comdconfirm); this.addcommand(comdback);trythis.append(新游戏,image.createimage(/img/icon.jpg);this.append(游戏排行,image.createimage(/img/icon.jpg);this.append(游戏说明,image.createimage(/img/icon.jpg);catch(illegalargumentexception e) system.out.println(e);catch(ioexception e) system.out.println(e);4.1.5子菜单模块 (1)在新游戏模块中,玩家通过新建游戏开始游戏,主要程序代码如下:public class selectlevelmenu extends list public static command comdback = new command(返回,command.back,1); public static command comdcomit = new command(开始游戏,command.ok,1); public static int level_easy = 0; public static int level_normal = 1; public static int level_difficulty = 2; public static string level_easy_name = 简单; public static string level_normal_name = 一般; public static string level_difficulty_name = 困难; private static string title=请选择等级.; public selectlevelmenu() super(selectlevelmenu.title,choice.implicit); addcommand(comdback); addcommand(comdcomit); try image image = image.createimage(/img/icon.jpg); this.append(简单,image); this.append(一般,image); this.append(困难,image); catch(ioexception e) system.out.println(e); (2) 在游戏排行模块中,主要是记录玩家闯关的层数,如果该玩家没有闯过一关将不会有任何记录。该模块代码如下:public class placeincompetition extends alert public static command comdback = new command(返回,command.back,1); public static string title = 最高记录.; private string levelname = ; private string levelnum = ; public placeincompetition() super(placeincompetition.title); this.addcommand(comdback); this.settimeout(alert.forever); string txt = ; try image image = image.createimage(/img/paiming.jpg); this.setimage(image); recordstore rec = null; recordenumeration en = null; try rec = recordstore.openrecordstore(test.recordstore_easy,false); en = rec.enumeraterecords(null,null,false); int m=0; while(en.haspreviouselement() if(m = 0) levelname = new string(en.previousrecord(); if(m = 1) levelnum = new string(en.previousrecord(); break; m+; rec.closerecordstore(); txt += levelname+: 第 +levelnum+ 关n; catch(exception e) txt += selectlevelmenu.level_easy_name +: +第 0 关n; try rec = recordstore.openrecordstore(test.recordstore_normal,false); en = rec.enumeraterecords(null,null,false); int m=0; while(en.haspreviouselement() if(m = 0) levelname = new string(en.previousrecord(); if(m = 1) levelnum = new string(en.previousrecord(); break; m+; rec.closerecordstore(); txt += levelname+: 第 +levelnum+ 关n; catch(exception e) txt += selectlevelmenu.level_normal_name +: +第 0 关n; try rec = recordstore.openrecordstore(test.recordstore_difficulty,false); en = rec.enumeraterecords(null,null,false); int m=0; while(en.haspreviouselement() if(m = 0) levelname = new string(en.previousrecord(); if(m = 1) levelnum = new string(en.previousrecord(); break; m+; rec.closerecordstore(); txt += levelname+: 第 +levelnum+ 关n; catch(exception e) txt += selectlevelmenu.level_difficulty_name +: +第 0 关n; catch(exception e) system.out.println(e); this.setstring(txt); (3) 在游戏说明模块中,主要就是介绍该款游戏的玩法和等级,以及难度系数介绍。主要代码如下:public class description extends alert private command comdback = new command(返回,command.back,1); private string imagepath = ; private string content = ; public description() super(游戏说明); this.addcommand(comdback); this.settimeout(alert.forever); parse();try if( !.equals(imagepath) ) image image = image.createimage(imagepath); this.setimage(image); catch(ioexception e) system.out.println(e); setstring(content); private void parse() inputstream inputstream = null; try inputstream = this.getclass().getresourceasstream(/description.xml); parsexml parsexml = new parsexml(inputstream); if(null != parsexml.get(description) imagepath = (string)(hashtable)parsexml.get(description).get(image); content = (string)(hashtable)parsexml.get(description).get(desc); catch(exception e) system.out.println(load description.xml error); 5 系统结果测试 (1) 在eclipse中“运行”测试代码,显示
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年湖南长沙市一中青竹湖湘一教育集团公开招聘教师50人模拟试卷及答案详解(夺冠系列)
- 2025年湖北医药学院专项公开招聘第二批工作人员11人模拟试卷及一套参考答案详解
- 2025江苏盐城市东台市教育局直属学校招聘教师、教练员58人考前自测高频考点模拟试题及完整答案详解
- 2025年福建省泉州市晋江市反邪教协会招聘1人模拟试卷附答案详解(黄金题型)
- 2025福建厦门红宝石投资管理有限公司社会招聘工程管理岗1人模拟试卷附答案详解(完整版)
- 2025湖南科技学院公开招聘44人考前自测高频考点模拟试题及1套参考答案详解
- 2025广西贺州市商务局公开招聘1人考前自测高频考点模拟试题及答案详解1套
- 广东省【中职专业高考】2025年中职高考对口升学(理论考试)真题卷【医药卫生大类】模拟练习
- 小学复学安全培训方案课件
- Hydroquinone-d6-Quinol-d-sub-6-sub-生命科学试剂-MCE
- 食品安全事故流行病学个案调查表
- 风机运行记录表
- 2021新高考语文Ⅰ卷现代文阅读Ⅱ小说《石门阵》赏析及试题详细解析
- 高中必修人教A版高中数学必修1指数函数一 完整版课件PPT
- 法律谈判实务完整版课件全套教学ppt教程
- PowerSurfacing 威力曲面 中文教程
- 2022藤椒油炒饭抖音推广方案-57P
- 报废机动车拆解有限公司应急预案
- 资产评估重点公式
- 杭州市区楼宇经济业态规划
- FMEA第五版(实例2)
评论
0/150
提交评论