基于ANDROID的简单扫雷小游戏Word文档下载推荐.doc
- 文档编号:470739
- 上传时间:2023-04-29
- 格式:DOC
- 页数:33
- 大小:2.32MB
基于ANDROID的简单扫雷小游戏Word文档下载推荐.doc
《基于ANDROID的简单扫雷小游戏Word文档下载推荐.doc》由会员分享,可在线阅读,更多相关《基于ANDROID的简单扫雷小游戏Word文档下载推荐.doc(33页珍藏版)》请在冰点文库上搜索。
(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<
numberOfRowsInMineField+1;
row++)
{
TableRowtableRow=newTableRow(this);
tableRow.setLayoutParams(newLayoutParams((blockDimension+2*blockPadding)*numberOfColumnsInMineField,blockDimension+2*blockPadding));
for(intcolumn=1;
column<
numberOfColumnsInMineField+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;
minesToFind=0;
privatevoidcreateMineField()
//wetakeonerowextrarowforeachside
//overalltwoextrarowsandtwoextracolumns
//firstandlastrow/columnareusedforcalculationspurposesonly
// x|xxxxxxxxxxxxxx|x
// ------------------
// x||x
//therowandcolumnsmarkedasxarejustusedtokeepcountsofnearbymines
blocks=newBlock[numberOfRowsInMineField+2][numberOfColumnsInMineField+2];
for(introw=0;
numberOfRowsInMineField+2;
for(intcolumn=0;
numberOfColumnsInMineField+2;
{
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
areMinesSet)
areMinesSet=true;
setMines(currentRow,currentColumn);
//thisisnotfirstclick
//checkifcurrentblockisflagged
//ifflaggedthedon'
tdoanything
//asthatoperationishandledbyLongClick
//ifblockisnotflaggedthenuncovernearbyblocks
//tillwegetnumberedmines
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
blocks[currentRow][currentColumn].isCovered()&
&
(blocks[currentRow][currentColumn].getNumberOfMinesInSorrounding()>
0)&
!
isGameOver)
intnearbyFlaggedBlocks=0;
for(intpreviousRow=-1;
previousRow<
2;
previousRow++)
for(intpreviousColumn=-1;
previousColumn<
previousColumn++)
{
if(blocks[currentRow+previousRow][currentColumn+previousColumn].isFlagged())
{
nearbyFlaggedBlocks++;
}
}
//ifflaggedblockcountisequaltonearbyminecount
//thenopennearbyblocks
if(nearbyFlaggedBlocks==blocks[currentRow][currentColumn].getNumberOfMinesInSorrounding())
for(intpreviousRow=-1;
for(intpreviousColumn=-1;
//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].setBlockAsDisabled(true);
blocks[currentRow][currentColumn].setQuestionMarkIcon(true);
blocks[currentRow][currentColumn].setFlagged(false);
blocks[currentRow][currentColumn].setQuestionMarked(true);
minesToFind++;
//increaseminecount
//case3.changetoblanksquare
else
blocks[currentRow][currentColumn].clearAllIcons();
blocks[currentRow][currentColumn].setQuestionMarked(false);
//ifitisflaggedthenincrementminecount
if(blocks[currentRow][currentColumn].isFlagged())
minesToFind++;
updateMineCountDisplay();
//removeflaggedstatus
updateMineCountDisplay();
//updateminedisplay
returntrue;
privatevoidwinGame()
isGameOver=true;
//setminecountto0
//seticontocooldude
btnSmile.setBackgroundResource(R.drawable.
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 基于 ANDROID 简单 扫雷 小游戏