基于ANDROID的简单扫雷小游戏.doc

上传人:聆听****声音 文档编号:355812 上传时间:2023-04-29 格式:DOC 页数:33 大小:2.32MB
下载 相关 举报
基于ANDROID的简单扫雷小游戏.doc_第1页
第1页 / 共33页
基于ANDROID的简单扫雷小游戏.doc_第2页
第2页 / 共33页
基于ANDROID的简单扫雷小游戏.doc_第3页
第3页 / 共33页
基于ANDROID的简单扫雷小游戏.doc_第4页
第4页 / 共33页
基于ANDROID的简单扫雷小游戏.doc_第5页
第5页 / 共33页
基于ANDROID的简单扫雷小游戏.doc_第6页
第6页 / 共33页
基于ANDROID的简单扫雷小游戏.doc_第7页
第7页 / 共33页
基于ANDROID的简单扫雷小游戏.doc_第8页
第8页 / 共33页
基于ANDROID的简单扫雷小游戏.doc_第9页
第9页 / 共33页
基于ANDROID的简单扫雷小游戏.doc_第10页
第10页 / 共33页
基于ANDROID的简单扫雷小游戏.doc_第11页
第11页 / 共33页
基于ANDROID的简单扫雷小游戏.doc_第12页
第12页 / 共33页
基于ANDROID的简单扫雷小游戏.doc_第13页
第13页 / 共33页
基于ANDROID的简单扫雷小游戏.doc_第14页
第14页 / 共33页
基于ANDROID的简单扫雷小游戏.doc_第15页
第15页 / 共33页
基于ANDROID的简单扫雷小游戏.doc_第16页
第16页 / 共33页
基于ANDROID的简单扫雷小游戏.doc_第17页
第17页 / 共33页
基于ANDROID的简单扫雷小游戏.doc_第18页
第18页 / 共33页
基于ANDROID的简单扫雷小游戏.doc_第19页
第19页 / 共33页
基于ANDROID的简单扫雷小游戏.doc_第20页
第20页 / 共33页
亲,该文档总共33页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

基于ANDROID的简单扫雷小游戏.doc

《基于ANDROID的简单扫雷小游戏.doc》由会员分享,可在线阅读,更多相关《基于ANDROID的简单扫雷小游戏.doc(33页珍藏版)》请在冰点文库上搜索。

基于ANDROID的简单扫雷小游戏.doc

大庆师范学院

《ANDROID应用设计》

课程设计报告

题目:

基于ANDROID的简单扫雷小游戏

专业班级:

计算机科学与技术(嵌入式方向)

设计者:

王珂:

201101041172

王盼盼:

201101041173

赵玉莹:

201101041183

刘阳:

201101041184

李若男:

201101041185

指导老师:

许有军

设计时间:

2013-2014

(1)

报告完成日期2013年12月20日

一.设计任务及要求(小三黑体)(段前0.5行,段后0.5行,下同)

1、设计任务

(1)系统会在雷区的某些小方框中随机布小若干个地雷。

安放地雷的小方块称之为雷方块,其他的称之为非雷方块。

部署完毕后,系统会在其他非雷方块中填充一些数字,某一个具体数字代表与其紧邻的8个方块中有多少个雷方块。

(2)游戏人可以根据

(1)中的信息去判断是否可以打开某些方块,并把认为是地雷的方块打上标识。

(3)游戏开始后,雷区上方有两个计数器。

左边的计数器显示用户扫雷所花的总时间,以秒为单位,

(4)当玩家将所有的地雷找出后,其余的地雷方块区都已打开,此时游戏结束。

(5)在游戏的过程中,一旦错误的打开了雷方块则立即失败,游戏结束。

2、设计要求

能够运用android语言设计出扫雷游戏的程序,会搭建android开发环境;

会创建自己的android项目生成的文件之间的关系和他们的作用,会使用各种控件;

能够对程序进行调试并学会修改其中的错误。

3、任务分配

王珂:

王盼盼;

赵玉莹:

刘阳:

李若男:

二.设计原理及总体框图

×××××××××(小4号宋体,1.5倍行距)××××××××××××××××××××………

1、实现原理:

扫雷是一个简单的单人游戏,游戏的目的实在没有触碰任何一个地雷的情形下清空一个雷区。

在扫雷游戏中,游戏者。

2、设计的总体框图:

包括在此说明设计的总体框图及实现原理

三.程序设计

1、程序分析

游戏界面设计:

在main.xml中加入三个TableRow,将整体界面划分为三个部分。

第一个TableRow中加入两个textview(Timer和MineCount),分别用来显示玩游戏话费的时间(以秒为单位)和雷方块的个数。

再加入一个button(Smiley),用来显示图片。

第二个TableRow中加入一个textview,用来将第一个部分和第二个部分分开。

第三个TableRow中加入一个TableLayout(MineField),用来显示扫雷区的框架。

程序的class类:

Blocked.Java和MinesweeperGame.java

程序的主要函数:

游戏开始函数:

startNewGame();

游戏显示函数:

showMineFiled();

创建新游戏函数:

createMineFiled();

完成游戏函数:

finishGame();

设置时间函数:

setmines();

玩家胜利函数:

winGame();

玩家失败函数:

endExistingGame();

2、程序详解

(1)游戏开始函数startNewGame

privatevoidstartNewGame()

{

//plantminesanddorestofthecalculations

createMineField();

//displayallblocksinUI

showMineField();

minesToFind=totalNumberOfMines;

isGameOver=false;

secondsPassed=0;

}

privatevoidshowMineField()

{

//rememberwewillnotshow0thandlastRowandColumns

//theyareusedforcalculationpurposesonly

for(introw=1;row

{

TableRowtableRow=newTableRow(this);

tableRow.setLayoutParams(newLayoutParams((blockDimension+2*blockPadding)*numberOfColumnsInMineField,blockDimension+2*blockPadding));

for(intcolumn=1;column

{

blocks[row][column].setLayoutParams(newLayoutParams(

blockDimension+2*blockPadding,

blockDimension+2*blockPadding));

blocks[row][column].setPadding(blockPadding,blockPadding,blockPadding,blockPadding);

tableRow.addView(blocks[row][column]);

}

mineField.addView(tableRow,newTableLayout.LayoutParams(

(blockDimension+2*blockPadding)*numberOfColumnsInMineField,blockDimension+2*blockPadding));

}

}

privatevoidendExistingGame()

{

stopTimer();//stopiftimerisrunning

txtTimer.setText("000");//revertalltext

txtMineCount.setText("010");//revertminescount

btnSmile.setBackgroundResource(R.drawable.smile);

//removeallrowsfrommineFieldTableLayout

mineField.removeAllViews();

//setallvariablestosupportendofgame

isTimerStarted=false;

areMinesSet=false;

isGameOver=false;

minesToFind=0;

}

privatevoidcreateMineField()

{

//wetakeonerowextrarowforeachside

//overalltwoextrarowsandtwoextracolumns

//firstandlastrow/columnareusedforcalculationspurposesonly

// x|xxxxxxxxxxxxxx|x

// ------------------

// x||x

// x||x

// ------------------

// x|xxxxxxxxxxxxxx|x

//therowandcolumnsmarkedasxarejustusedtokeepcountsofnearbymines

blocks=newBlock[numberOfRowsInMineField+2][numberOfColumnsInMineField+2];

for(introw=0;row

{

for(intcolumn=0;column

{

blocks[row][column]=newBlock(this);

blocks[row][column].setDefaults();

//passcurrentrowandcolumnnumberasfinalint'stoeventlisteners

//thiswaywecanensurethateacheventlistenerisassociatedto

//particularinstanceofblockonly

finalintcurrentRow=row;

finalintcurrentColumn=column;

//addClickListener

//thisistreatedasLeftMouseclick

blocks[row][column].setOnClickListener(newOnClickListener()

{

@Override

publicvoidonClick(Viewview)

{

//starttimeronfirstclick

if(!

isTimerStarted)

{

startTimer();

isTimerStarted=true;

}

//setminesonfirstclick

if(!

areMinesSet)

{

areMinesSet=true;

setMines(currentRow,currentColumn);

}

//thisisnotfirstclick

//checkifcurrentblockisflagged

//ifflaggedthedon'tdoanything

//asthatoperationishandledbyLongClick

//ifblockisnotflaggedthenuncovernearbyblocks

//tillwegetnumberedmines

if(!

blocks[currentRow][currentColumn].isFlagged())

{

//opennearbyblockstillwegetnumberedblocks

rippleUncover(currentRow,currentColumn);

//didweclickedamine

if(blocks[currentRow][currentColumn].hasMine())

{

//Oops,gameover

finishGame(currentRow,currentColumn);

}

//checkifwewinthegame

if(checkGameWin())

{

//markgameaswin

winGame();

}

}

}

});

//addLongClicklistener

//thisistreatedasrightmouseclicklistener

blocks[row][column].setOnLongClickListener(newOnLongClickListener()

{

publicbooleanonLongClick(Viewview)

{

//simulatealeft-right(middle)click

//ifitisalongclickonanopenedminethen

//openallsurroundingblocks

if(!

blocks[currentRow][currentColumn].isCovered()&&(blocks[currentRow][currentColumn].getNumberOfMinesInSorrounding()>0)&&!

isGameOver)

{

intnearbyFlaggedBlocks=0;

for(intpreviousRow=-1;previousRow<2;previousRow++)

{

for(intpreviousColumn=-1;previousColumn<2;previousColumn++)

{

if(blocks[currentRow+previousRow][currentColumn+previousColumn].isFlagged())

{

nearbyFlaggedBlocks++;

}

}

}

//ifflaggedblockcountisequaltonearbyminecount

//thenopennearbyblocks

if(nearbyFlaggedBlocks==blocks[currentRow][currentColumn].getNumberOfMinesInSorrounding())

{

for(intpreviousRow=-1;previousRow<2;previousRow++)

{

for(intpreviousColumn=-1;previousColumn<2;previousColumn++)

{

//don'topenflaggedblocks

if(!

blocks[currentRow+previousRow][currentColumn+previousColumn].isFlagged())

{

//openblockstillwegetnumberedblock

rippleUncover(currentRow+previousRow,currentColumn+previousColumn);

//didweclickedamine

if(blocks[currentRow+previousRow][currentColumn+previousColumn].hasMine())

{

//oopsgameover

finishGame(currentRow+previousRow,currentColumn+previousColumn);

}

//didwewinthegame

if(checkGameWin())

{

//markgameaswin

winGame();

}

}

}

}

}

//aswenolongerwanttojudgethisgesturesoreturn

//notreturningfromherewillactuallytriggerotheraction

//whichcanbemarkingasaflagorquestionmarkorblank

returntrue;

}

//ifclickedblockisenabled,clickableorflagged

if(blocks[currentRow][currentColumn].isClickable()&&

(blocks[currentRow][currentColumn].isEnabled()||blocks[currentRow][currentColumn].isFlagged()))

{

//forlongclicksset:

//1.emptyblockstoflagged

//2.flaggedtoquestionmark

//3.questionmarktoblank

//case1.setblankblocktoflagged

if(!

blocks[currentRow][currentColumn].isFlagged()&&!

blocks[currentRow][currentColumn].isQuestionMarked())

{

blocks[currentRow][currentColumn].setBlockAsDisabled(false);

blocks[currentRow][currentColumn].setFlagIcon(true);

blocks[currentRow][currentColumn].setFlagged(true);

minesToFind--;//reduceminecount

updateMineCountDisplay();

}

//case2.setflaggedtoquestionmark

elseif(!

blocks[currentRow][currentColumn].isQuestionMarked())

{

blocks[currentRow][currentColumn].setBlockAsDisabled(true);

blocks[currentRow][currentColumn].setQuestionMarkIcon(true);

blocks[currentRow][currentColumn].setFlagged(false);

blocks[currentRow][currentColumn].setQuestionMarked(true);

minesToFind++;//increaseminecount

updateMineCountDisplay();

}

//case3.changetoblanksquare

else

{

blocks[currentRow][currentColumn].setBlockAsDisabled(true);

blocks[currentRow][currentColumn].clearAllIcons();

blocks[currentRow][currentColumn].setQuestionMarked(false);

//ifitisflaggedthenincrementminecount

if(blocks[currentRow][currentColumn].isFlagged())

{

minesToFind++;//increaseminecount

updateMineCountDisplay();

}

//removeflaggedstatus

blocks[currentRow][currentColumn].setFlagged(false);

}

updateMineCountDisplay();//updateminedisplay

}

returntrue;

}

});

}

}

}

privatevoidwinGame()

{

stopTimer();

isTimerStarted=false;

isGameOver=true;

minesToFind=0;//setminecountto0

//seticontocooldude

btnSmile.setBackgroundResource(R.drawable.

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

当前位置:首页 > 自然科学 > 物理

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

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