1、5)居于多线程,实现进度条2.2游戏功能划分游戏的基本功能应该包括菜单处理,程序逻辑处理,持久性处理和挂起恢复处理。关于菜单的处理,包括可以选择的进入游戏、保存、帮助和音效开关等。程序的逻辑处理就是涵盖了程序中除菜单外几乎所有的功能。持久性处理就是资源的载入和游戏的进度保存。2.3功能划分的架构图2.4具体的功能模块1)游戏控制模块2)查询记录模块3)关卡选择模块4)游戏设置模块2.5功能描述玩家打开程序,在游戏菜单页面有四个选项。关卡选择:选择已玩过的关卡进行游戏;开始游戏:从游戏的第一关进行游戏,玩家通过按键控制主人公马里奥进行不同的操作;查询记录:查询五个最高游戏分数,排名由上往下递减。
2、游戏设置(包括音乐设置和按键设置):玩家可以设置游戏进行时的音乐开或关以及修改相应的控制键。2.6程序的总体架构本程序采用3层程序架构,业务表现层,业务逻辑层和数据持久层。业务表现层。主要是游戏界面的绘制,通过指定的接口绘制,与游戏的逻辑分离。业务逻辑层。主要是游戏的人物和敌人的动作,碰撞的判断,这个与表现层无关,需要表示层调用定义好的接口与逻辑层的通信数据持久层。保存游戏中的数据,载入游戏中需要的资源,与程序逻辑层无关,用XML文档存储数据2.7程序的三层结构图 3.面向对象设计3.1主要类图3.2各个模块的方法或类名类表示3.3地图绘制中的坐标说明4.程序的详细设计部分源代码如下:4.1主
3、要人物玛丽的实现 package org.liky.mario;import java.awt.image.BufferedImage;public class Mario implements Runnable /坐标 private int x; private int y; /定义一个场景对象来保存mario当前所处的场景对象 private BackGround bg; /加入线程 private Thread t=null; /移动速度 private int xmove=0; private int ymove=0; /状态 private String status; /显示的图
4、片 private BufferedImage showImage; /生命数和分数 private int life; private int score; /当前移动中显示的图片数 private int moving=0; private int upTime=0; /标记mario是否死亡 private boolean isDead=false; /标记玩家是否完成了全部的游戏 private boolean isClear=false; public Mario(int x,int y) this.x=x; this.y=y; /初始化Mario图片 this.showImage=
5、StaticValue.allMarioImage.get(0); this.score=0; this.life=3; t=new Thread(this); this.status=right-standing; t.start(); public void leftMove() /改变速度 this.xmove=-30; /改变状态 /如果当前已经是跳跃状态,应该保留原有状态,不应该改变状态 if(this.status.indexOf(jumping)!=-1) this.status=left-jumping elseleft-moving public void rightMove
6、() this.xmove=30;right-jumpingright-moving public void leftStop() this.xmove=0;left-standing public void rightStop() public void jump()=-1) if(this.status.indexOf(left this.status= else ymove=-30; upTime=6; public void down() ymove=30; /mario的死亡方法 public void dead() this.life-; if(this.life=0) this.
7、showImage=StaticValue.mariodeadImage; this.isDead=true; else this.bg.reset(); this.x=0; this.y=480; public int getX() return x; public int getY() return y; public void setX(int x) this.x = x; public void setY(int y) this.y = y; public BufferedImage getShowImage() return showImage; public void run()
8、/ TODO Auto-generated method stub while(true) if(this.bg.isFlag()&this.x=508) /如果为最后一个场景,同时mario的坐标到达了508,则游戏结束 /自动控制游戏结束的移动 this.bg.setOver(true); if(this.bg.isDown() /降旗后,mario开始向城门移动 this.status= if(this.x568) /mario只向右移动 this.x+=30; else if(this.y762) /游戏结束,已经完成了全部的场景 this.isClear=true; else if(
9、this.y=420) this.y=420; this.status= else /判断当前mario是否与障碍物碰撞 /定义标记 boolean canLeft=true; boolean canRight=true; /定义一个mario当前是否处于障碍物上的标记 boolean onLand=false; for(int i=0;ithis.y&ob.getY()-50this.x&ob.getX()-600) if(ob.getY()=this.y-60&(ob.getX()+50ob.getX()-50this.x)&(e.getX()-50e.getY()-60e.getX()-
10、50600) this.dead(); if(canLeft=true & xmove0) /改变坐标 x+=xmove; if(x x=0; /定义一个图片取得的初始索引值 int temp=0; /判断mario是否面向左 temp+=5; /判断mario是否移动moving temp+=this.moving; moving+; if(moving=4) moving=0; temp+=4; /改变显示图片 this.showImage=StaticValue.allMarioImage.get(temp); try Thread.sleep(100); catch(Interrupt
11、edException e) e.printStackTrace(); if(this.score=500) this.life+; this.score=0; public void setBg(BackGround bg) this.bg = bg; public boolean isDead() return isDead; public int getLife() return life; public void setLife(int life) this.life = life; public int getScore() return score; public void setScore(int score) this.score = score; public boolean isClear() return isClear;
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1