超级玛丽详细设计文档.docx
《超级玛丽详细设计文档.docx》由会员分享,可在线阅读,更多相关《超级玛丽详细设计文档.docx(18页珍藏版)》请在冰豆网上搜索。
超级玛丽详细设计文档
超级玛丽详细设计文档
超级玛丽JAVA小游戏详细设计
超级玛丽JAVA小游戏详细设计
1.导言
1.1编写目的
该文档的目的是说明超级玛丽游戏的功能和设计方向、目标等描述游戏项目的整体框架的实现。
其主要内容包括:
游戏项目的功能简介,接口设计,模块设计,界面设计。
本文档预期读者包括:
项目管理人员,编程人员,数据库设计人员,美工,测试人员。
1.2项目范围
该文档定义了游戏的模块,结构单元,但未确定单元的实现方法,这部分内容将在具体的代码设计中实现。
1.3参考资料
《java语言程序设计》清华大学出版社郎波编著
1.4缩写说明
UML:
UnifiedModelingLanguage(统一建模语言)的缩写,是一个标准的建模语言。
1.5术语定义
MIDP2.0定义:
MIDP2.0也叫MIDP_NG,它的编号是JSR118。
MIDP2.0与1.0相比有很大提高,增加的特性包括:
提供域安全模型,以允许对应用程序进行签名和论证;提供TCP、UDP网络接口;内置OTA;更好的用户界面;基本的声音API。
2.功能需求
2.1界面设计技术
1)选取和谐Q版的图片,使画面色彩和谐自然,配合动听的音乐渲染游戏气氛
2)采用对话框方式,多功能窗口运行,固定窗口大小便于程序编写,键盘操作游戏角色。
3)使用低级用户界面,响应低级用户事件,不使用MIDP2.0GameAPI
4)地图数据采用char类型,对每一个地图块的大小为16×16像素,采用单层地图,以提高游戏的运行速度
5)居于多线程,实现进度条
2.2游戏功能划分
游戏的基本功能应该包括菜单处理,程序逻辑处理,持久性处理和挂起恢复处理。
◆关于菜单的处理,包括可以选择的进入游戏、保存、帮助和音效开关等。
◆程序的逻辑处理就是涵盖了程序中除菜单外几乎所有的功能。
◆持久性处理就是资源的载入和游戏的进度保存。
2.3功能划分的架构图
2.4具体的功能模块
1)游戏控制模块
2)查询记录模块
3)关卡选择模块
4)游戏设置模块
2.5功能描述
玩家打开程序,在游戏菜单页面有四个选项。
◆关卡选择:
选择已玩过的关卡进行游戏;
◆开始游戏:
从游戏的第一关进行游戏,玩家通过按键控制主人公马里奥进行不同的操作;
◆查询记录:
查询五个最高游戏分数,排名由上往下递减。
◆游戏设置(包括音乐设置和按键设置):
玩家可以设置游戏进行时的音乐开或关以及修改相应的控制键。
2.6程序的总体架构
本程序采用3层程序架构,业务表现层,业务逻辑层和数据持久层。
◆业务表现层。
主要是游戏界面的绘制,通过指定的接口绘制,与游戏的逻辑分离。
◆业务逻辑层。
主要是游戏的人物和敌人的动作,碰撞的判断,这个与表现层无关,需要表示层调用定义好的接口与逻辑层的通信
◆数据持久层。
保存游戏中的数据,载入游戏中需要的资源,与程序逻辑层无关,用XML文档存储数据
2.7程序的三层结构图
3.面向对象设计
3.1主要类图
3.2各个模块的方法或类名类表示
3.3地图绘制中的坐标说明
4.程序的详细设计
部分源代码如下:
4.1主要人物玛丽的实现
packageorg.liky.mario;
importjava.awt.image.BufferedImage;
publicclassMarioimplementsRunnable{
//坐标
privateintx;
privateinty;
//定义一个场景对象来保存mario当前所处的场景对象
privateBackGroundbg;
//加入线程
privateThreadt=null;
//移动速度
privateintxmove=0;
privateintymove=0;
//状态
privateStringstatus;
//显示的图片
privateBufferedImageshowImage;
//生命数和分数
privateintlife;
privateintscore;
//当前移动中显示的图片数
privateintmoving=0;
privateintupTime=0;
//标记mario是否死亡
privatebooleanisDead=false;
//标记玩家是否完成了全部的游戏
privatebooleanisClear=false;
publicMario(intx,inty){
this.x=x;
this.y=y;
//初始化Mario图片
this.showImage=StaticValue.allMarioImage.get(0);
this.score=0;
this.life=3;
t=newThread(this);
this.status="right--standing";
t.start();
}
publicvoidleftMove(){
//改变速度
this.xmove=-30;
//改变状态
//如果当前已经是跳跃状态,应该保留原有状态,不应该改变状态
if(this.status.indexOf("jumping")!
=-1){
this.status="left--jumping";
}
else{
this.status="left--moving";
}
}
publicvoidrightMove(){
this.xmove=30;
//如果当前已经是跳跃状态,应该保留原有状态,不应该改变状态
if(this.status.indexOf("jumping")!
=-1){
this.status="right--jumping";
}
else{
this.status="right--moving";
}
}
publicvoidleftStop(){
this.xmove=0;
//如果当前已经是跳跃状态,应该保留原有状态,不应该改变状态
if(this.status.indexOf("jumping")!
=-1){
this.status="left--jumping";
}
else{
this.status="left--standing";
}
}
publicvoidrightStop(){
this.xmove=0;
//如果当前已经是跳跃状态,应该保留原有状态,不应该改变状态
if(this.status.indexOf("jumping")!
=-1){
this.status="right--jumping";
}
else{
this.status="right--standing";
}
}
publicvoidjump(){
if(this.status.indexOf("jumping")==-1){
if(this.status.indexOf("left")!
=-1){
this.status="left--jumping";
}
else{
this.status="right--jumping";
}
ymove=-30;
upTime=6;
}
}
publicvoiddown(){
if(this.status.indexOf("left")!
=-1){
this.status="left--jumping";
}
else{
this.status="right--jumping";
}
ymove=30;
}
//mario的死亡方法
publicvoiddead(){
this.life--;
if(this.life==0){
this.showImage=StaticValue.mariodeadImage;
this.isDead=true;
}else{
this.bg.reset();
this.x=0;
this.y=480;
}
}
publicintgetX(){
returnx;
}
publicintgetY(){
returny;
}
publicvoidsetX(intx){
this.x=x;
}
publicvoidsetY(inty){
this.y=y;
}
publicBufferedImagegetShowImage(){
returnshowImage;
}
publicvoidrun(){
//TODOAuto-generatedmethodstub
while(true){
if(this.bg.isFlag()&&this.x>=508){
//如果为最后一个场景,同时mario的坐标到达了508,则游戏结束
//自动控制游戏结束的移动
this.bg.setOver(true);
if(this.bg.isDown()){
//降旗后,mario开始向城门移动
this.status="right--moving";
if(this.x<568){
//mario只向右移动
this.x+=30;
}else{
if(this.y<480){
//mario向下移动
this.y+=30;
}
this.x+=30;
if(this.x>762){
//游戏结束,已经完成了全部的场景
this.isClear=true;
}
}
}else{
if(this.y<420){
this.y+=30;
}
if(this.y>=420){
this.y=420;
this.status="right--standing";
}
}
}else{
//判断当前mario是否与障碍物碰撞
//定义标记
booleancanLeft=true;
booleancanRight=true;
//定义一个mario当前是否处于障碍物上的标记
booleanonLand=false;
for(inti=0;iObstructionob=this.bg.getAllObstruction().get(i);
//如果mario和障碍物相切则不允许mario继续向右移动
if((ob.getX()==this.x+60)
&&(ob.getY()+50>this.y&&ob.getY()-50if(ob.getType()!
=3){
canRight=false;
}
}
//不允许mario继续向左移动
if((ob.getX()==this.x-60)
&&(ob.getY()+50>this.y&&ob.getY()-50if(ob.getType()!
=3){
canLeft=false;
}
}
//如果符合条件则表明mario当前处在障碍物上面
if(ob.getY()==this.y+60
&&(ob.getX()+60>this.x&&ob.getX()-60if(ob.getType()!
=3){
onLand=true;
}
}
//判断当前mario在跳跃过程中是否顶到了障碍物
if(upTime>0){
if(ob.getY()==this.y-60&&(ob.getX()+50>this.x&&ob.getX()-50//对于砖块处理
if(ob.getType()==0){
//将该砖块从场景中移除
this.bg.getAllObstruction().remove(ob);
//将被移除的砖块保存到一个集合中
this.bg.getRemovedObstruction().add(ob);
//将分数加10
this.score+=10;
}
//对于问号的处理和对于隐藏的砖块的处理
if(ob.getType()==4||ob.getType()==3){
ob.setType
(2);
ob.setImage();
this.score+=50;
}
upTime=0;
}
}
}
//加入mario对敌人的判断
for(inti=0;iEnemye=this.bg.getAllEnemy().get(i);
if((e.getX()+50>this.x)&&(e.getX()-50this.y&&e.getY()-60//mario死亡
this.dead();
}
if(e.getY()==this.y+60&&(e.getX()+50>this.x&&e.getX()-50if(e.getType()==1||e.getType()==3){
e.dead();
this.upTime=2;
this.ymove=-30;
this.score+=50;
}elseif(e.getType()==2){
this.dead();
}
}
}
if(onLand&&upTime==0){
if(this.status.indexOf("left")!
=-1){
if(xmove==0){
this.status="left--standing";
}
else{
this.status="left--moving";
}
}
else{
if(xmove==0){
this.status="right--standing";
}
else{
this.status="right--moving";
}
}
}
else{
//表示当前为上升状态
if(upTime!
=0){
upTime--;
}else{
this.down();
}
y+=ymove;
}
if(this.y>600){
this.dead();
}
if(canLeft==true&&xmove<0||(canRight==true&&xmove>0)){
//改变坐标
x+=xmove;
if(x<0){
x=0;
}
}
}
//定义一个图片取得的初始索引值
inttemp=0;
//判断mario是否面向左
if(this.status.indexOf("left")!
=-1){
temp+=5;
}
//判断mario是否移动
if(this.status.indexOf("moving")!
=-1){
temp+=this.moving;
moving++;
}
if(moving==4){
moving=0;
}
if(this.status.indexOf("jumping")!
=-1){
temp+=4;
}
//改变显示图片
this.showImage=StaticValue.allMarioImage.get(temp);
try{
Thread.sleep(100);
}
catch(InterruptedExceptione){
e.printStackTrace();
}
if(this.score==500){
this.life++;
this.score=0;
}
}
}
publicvoidsetBg(BackGroundbg){
this.bg=bg;
}
publicbooleanisDead(){
returnisDead;
}
publicintgetLife(){
returnlife;
}
publicvoidsetLife(intlife){
this.life=life;
}
publicintgetScore(){
returnscore;
}
publicvoidsetScore(intscore){
this.score=score;
}
publicbooleanisClear(){
returnisClear;
}
}