安卓贪吃蛇游戏方案设计书Word格式.docx

上传人:b****1 文档编号:5073151 上传时间:2023-05-04 格式:DOCX 页数:45 大小:989.04KB
下载 相关 举报
安卓贪吃蛇游戏方案设计书Word格式.docx_第1页
第1页 / 共45页
安卓贪吃蛇游戏方案设计书Word格式.docx_第2页
第2页 / 共45页
安卓贪吃蛇游戏方案设计书Word格式.docx_第3页
第3页 / 共45页
安卓贪吃蛇游戏方案设计书Word格式.docx_第4页
第4页 / 共45页
安卓贪吃蛇游戏方案设计书Word格式.docx_第5页
第5页 / 共45页
安卓贪吃蛇游戏方案设计书Word格式.docx_第6页
第6页 / 共45页
安卓贪吃蛇游戏方案设计书Word格式.docx_第7页
第7页 / 共45页
安卓贪吃蛇游戏方案设计书Word格式.docx_第8页
第8页 / 共45页
安卓贪吃蛇游戏方案设计书Word格式.docx_第9页
第9页 / 共45页
安卓贪吃蛇游戏方案设计书Word格式.docx_第10页
第10页 / 共45页
安卓贪吃蛇游戏方案设计书Word格式.docx_第11页
第11页 / 共45页
安卓贪吃蛇游戏方案设计书Word格式.docx_第12页
第12页 / 共45页
安卓贪吃蛇游戏方案设计书Word格式.docx_第13页
第13页 / 共45页
安卓贪吃蛇游戏方案设计书Word格式.docx_第14页
第14页 / 共45页
安卓贪吃蛇游戏方案设计书Word格式.docx_第15页
第15页 / 共45页
安卓贪吃蛇游戏方案设计书Word格式.docx_第16页
第16页 / 共45页
安卓贪吃蛇游戏方案设计书Word格式.docx_第17页
第17页 / 共45页
安卓贪吃蛇游戏方案设计书Word格式.docx_第18页
第18页 / 共45页
安卓贪吃蛇游戏方案设计书Word格式.docx_第19页
第19页 / 共45页
安卓贪吃蛇游戏方案设计书Word格式.docx_第20页
第20页 / 共45页
亲,该文档总共45页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

安卓贪吃蛇游戏方案设计书Word格式.docx

《安卓贪吃蛇游戏方案设计书Word格式.docx》由会员分享,可在线阅读,更多相关《安卓贪吃蛇游戏方案设计书Word格式.docx(45页珍藏版)》请在冰点文库上搜索。

安卓贪吃蛇游戏方案设计书Word格式.docx

贪吃蛇游戏就是一条小蛇,不停地在屏幕上游走,吃各个方向出现的食物,越吃越长。

只要蛇头碰到屏幕四周,或者碰到自己的身子,小蛇就立即毙命。

玩“贪吃蛇游戏”,难度最大的不是蛇长得很长的时候,而是开始的时候。

那时蛇身很短,看上去难度不大,却最容易死掉,因为把玩一条小蛇让人容易走神,失去耐心。

Android应用越来越广泛,开发Android游戏也渐渐成为市场的必须,本游戏的开发是基于Android1.5系统,采用eclipse编程实现。

2时间安排

消化资料、系统调查1天

系统分析、总体设计,实施计划5天

撰写报告 

2天

演示、验收           1天

3具体要求

1、明确课程设计的目的和重要性,认真领会课程设计的题目,读懂课程设计指导书的要求,学会设计的基本方法与步骤,学会如何运用前修知识与收集、归纳相关资料解决具体问题的方法。

严格要求自己,要独立思考,按时、独立完成课程设计任务。

2、设计报告:

要求层次清楚、整洁规范、不得相互抄袭,凡正文内容有整段完全相同者一律以抄袭论处。

4设计与实现

具体实现过程分为以下3步:

工程框架、游戏类图设计、界面设计。

工程框架

新建一个Eclipse工程并命名为Snake,工程如下图所示:

图1.1Snake工程

工程中包括4个Activity,分别为Snake(主界面)、Game(游戏界面)、Help(游戏说明界面)、AuthorView(作者信息界面),通过不同Activity之间的转换实现不同界面之间的切换。

游戏主界面如下图所示:

图1.2游戏主界面

游戏类图设计

Game(Activity)继承了SnakeView类,SnakeView类继承了TileView类。

TileView类继承了View,如下图所示:

图1.3类图

TiltView的基类是View,包含了贪吃蛇游戏画面的各个设定参数,主要负责绘制游戏画面。

TileView类定义如下:

publicclassTileViewextendsView{

privatestaticfinalStringtag="

yao"

protectedstaticintmTileSize=20。

//方格的边长

protectedstaticintmXTileCount。

//X轴上方格的个数

protectedstaticintmYTileCount。

//Y轴上方格的个数

privatestaticintmXOffset。

//绘图时X轴上的起始坐标

privatestaticintmYOffset。

//绘图时Y轴上的起始坐标

privateBitmap[]mTileArray。

//位图数组

privateint[][]mTileGrid。

//映射整个游戏画面的数组

privatefinalPaintmPaint=newPaint()。

//画笔

publicTileView(Contextcontext,AttributeSetattrs){

super(context,attrs)。

Log.i(tag,"

TileViewConstructor"

)。

mTileSize="

+mTileSize)。

}

//重置位图数组的长度

publicvoidresetTiles(inttilecount){

mTileArray=newBitmap[tilecount]。

@Override

//适应各种分辨率的屏幕,当改变屏幕大小尺寸时,同时修改tile的相关计数指标

protectedvoidonSizeChanged(intw,inth,intoldw,intoldh){

onSizeChanged,"

+"

w="

+w+"

h="

+h+"

oldw="

+oldw+"

oldh="

+oldh)。

mXTileCount=(int)Math.floor(w/mTileSize)。

mYTileCount=(int)Math.floor(h/mTileSize)。

mXTileCount="

+mXTileCount)。

mYTileCount="

+mYTileCount)。

mXOffset=((w-(mTileSize*mXTileCount))/2)。

mYOffset=((h-(mTileSize*mYTileCount))/2)。

mXOffset="

+mXOffset)。

mYOffset="

+mYOffset)。

mTileGrid=newint[mXTileCount][mYTileCount]。

clearTiles()。

//这里做了一个Drawable到bitmap的转换

publicvoidloadTile(intkey,Drawabletile){

Bitmapbitmap=Bitmap.createBitmap(mTileSize,mTileSize,Bitmap.Config.ARGB_8888)。

Canvascanvas=newCanvas(bitmap)。

tile.setBounds(0,0,mTileSize,mTileSize)。

tile.draw(canvas)。

mTileArray[key]=bitmap。

//清空图形显示

publicvoidclearTiles(){

TileView.clearTiles"

for(intx=0。

x<

mXTileCount。

x++){

for(inty=0。

y<

mYTileCount。

y++){

setTile(0,x,y)。

}

}

//在相应的坐标位置绘制相应的砖块

publicvoidsetTile(inttileindex,intx,inty){

mTileGrid[x][y]=tileindex。

//onDraw

//将直接操作的画布绘制到手机界面上

publicvoidonDraw(Canvascanvas){

onDraw"

super.onDraw(canvas)。

Bitmapbmp。

floatleft。

floattop。

if(mTileGrid[x][y]>

0){

bmp=mTileArray[mTileGrid[x][y]]。

left=x*mTileSize+mXOffset。

top=y*mTileSize+mYOffset。

canvas.drawBitmap(bmp,left,top,mPaint)。

}

}

SnakeView类定义了游戏运行时的画面改变及蛇体和果子的更新方法。

首先用Handler机制实现定时刷新,代码如下:

classRefreshHandlerextendsHandler{

//获取消息并处理

publicvoidhandleMessage(Messagemsg){

SnakeView.this.update()。

SnakeView.this.invalidate()。

//刷新view为基类的界面

Log.i(tag,"

handleMessage|ThreadName="

+Thread.currentThread().getName())。

//定时发送消息给UI线程,以此达到更新效果

publicvoidsleep(longdelayMillis){

this.removeMessages(0)。

//清空消息队列,Handler进入对新消息的等待

sleep|ThreadName="

//定时发送新消息,激活handler

sendMessageDelayed(obtainMessage(0),delayMillis)。

}。

定义SnakeView()函数初始化游戏,代码如下:

publicSnakeView(Contextcontext,AttributeSetattrs){

SnakeViewConstructor"

initSnakeView()。

//构造函数中,初始化游戏

定义initSnakeView()初始化SnakeView类,代码如下:

privatevoidinitSnakeView(){

Log.e(tag,"

initSnakeView"

//设置焦点,由于存在文字界面和游戏界面的跳转。

这个focus是不可或缺的。

setFocusable(true)。

//取得资源中的图片,加载到砖块字典中。

Resourcesr=this.getContext().getResources()。

resetTiles(4)。

loadTile(RED_STAR,r.getDrawable(R.drawable.redstar))。

loadTile(YELLOW_STAR,r.getDrawable(R.drawable.yellowstar))。

loadTile(GREEN_STAR,r.getDrawable(R.drawable.greenstar))。

此外还定义了updateWalls()、updateApples()、updateSnake()绘制墙、果子、蛇,以及更新画面函数、保存位置坐标函数等,具体代码请详见目录。

界面设计

界面设计包括游戏主界面(Snake)、作者信息界面、游戏说明界面、游戏界面的设计。

界面的设计采用的是xml文档形式,在xml文档中规划好界面布局布局后,分别在java文件中声明。

主界面设计:

主界面包括一个TextView、一个imagebutton、三个button,其main.xml文档如下:

<

?

xmlversion="

1.0"

encoding="

utf-8"

>

AbsoluteLayoutxmlns:

android="

"

android:

layout_width="

fill_parent"

layout_height="

background="

@drawable/icon"

LinearLayout

orientation="

vertical"

gravity="

center"

TextViewandroid:

textColor="

#ff3456ff"

textSize="

40sp"

wrap_content"

visibility="

visible"

text="

Snake"

id="

@+id/text"

center_horizontal"

/TextView>

ImageButton

@+id/ImageButton1"

/ImageButton>

Button

@+id/Button1"

/Button>

@+id/Button5"

@+id/Button3"

/LinearLayout>

/AbsoluteLayout>

其对应的Snake.java文件如下:

publicclassSnakeextendsActivity{

/**Calledwhentheactivityisfirstcreated.*/

publicvoidonCreate(BundlesavedInstanceState){

super.onCreate(savedInstanceState)。

setContentView(R.layout.main)。

initialstart()。

//初始化

publicvoidinitialstart(){

ImageButtonimageButton=(ImageButton)this.findViewById(R.id.ImageButton1)。

Buttonbutton1=(Button)this.findViewById(R.id.Button1)。

Buttonbutton3=(Button)this.findViewById(R.id.Button3)。

Buttonbutton5=(Button)this.findViewById(R.id.Button5)。

button1.setText("

作者信息"

button3.setText("

退出"

button5.setText("

游戏说明"

imageButton.setImageResource(R.drawable.icon1)。

//按钮注册到各自的监听器

imageButton.setOnClickListener(newView.OnClickListener(){

publicvoidonClick(Viewview){

Intentintent=newIntent()。

intent.setClass(Snake.this,Game.class)。

startActivity(intent)。

//跳转到Game界面

Snake.this.finish()。

})。

button1.setOnClickListener(newView.OnClickListener(){

//setContentView(R.layout.author)。

intent.setClass(Snake.this,AuthorView.class)。

//跳转到作者信息界面

//注销跳转之前的界面

button3.setOnClickListener(newView.OnClickListener(){

//退出应用程序

button5.setOnClickListener(newView.OnClickListener(){

intent.setClass(Snake.this,Help.class)。

//跳转到游戏说明界面

游戏界面设计:

游戏界面包括一个button,一个my.game.snake.SnakeView,其game.xml文档如下:

FrameLayoutxmlns:

my.game.snake.SnakeView

@+id/snake"

@drawable/background"

/>

RelativeLayoutandroid:

@+id/relativeLayout1"

#ff8888ff"

24sp"

开始"

layout_centerInParent="

true"

Buttonandroid:

返回"

@+id/button4"

layout_alignParentBottom="

/RelativeLayout>

/FrameLayout>

相对应的Game.java文件如下:

publicclassGameextendsActivity{

//定义游戏参数

privateSnakeViewmSnakeView。

privatestaticStringICICLE_KEY="

snake-view"

privateintmMode=READY。

publicstaticfinalintPAUSE=0。

publicstaticfinalintREADY=1。

publicstaticfinalintRUNNING=2。

publicstaticfinalintLOSE=3。

setContentView(R.layout.game)。

mSnakeView=(SnakeView)findViewById(R.id.snake)。

//设置界面背景

mSnakeView.setBackgroundResource(R.drawable.background)。

TextVie

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 总结汇报 > 学习总结

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2