扫雷程序设计报告文档格式.docx
- 文档编号:18627832
- 上传时间:2022-12-29
- 格式:DOCX
- 页数:22
- 大小:20.60KB
扫雷程序设计报告文档格式.docx
《扫雷程序设计报告文档格式.docx》由会员分享,可在线阅读,更多相关《扫雷程序设计报告文档格式.docx(22页珍藏版)》请在冰豆网上搜索。
1.bmp"
)
Fori=0Tom-1
Forj=0Ton-1
form1.pic2.PaintPicturepicf,j*16,i*16'
加载图片
Next
(2).放雷的方法:
定义一个二维数组aarMine,行数为inthang,列数为intlie,雷的个数intlei,使用下面的程序来解决:
Randomize
ReDimarrMine(inthang,intlie)
DoWhileint3<
intlei'
雷数的随机分布
col=Int(Rnd*intlie)
ln=Int(Rnd*inthang)
IfarrMine(ln,col)=FalseThen
arrMine(ln,col)=True
int3=int3+1
EndIf
Loop
(3).使用三个pictureclip控件来管理图片:
form1.PictureClip1.Picture=LoadPicture(App.Path&
face.bmp"
form1.PictureClip1.Rows=1
form1.PictureClip1.Cols=5
form1.PictureClip2.Picture=LoadPicture(App.Path&
number.bmp"
form1.PictureClip2.Rows=1
form1.PictureClip2.Cols=12
form1.PictureClip3.Picture=LoadPicture(App.Path&
mine.bmp"
form1.PictureClip3.Rows=1
form1.PictureClip3.Cols=15
(4).使用递归过程(fangkai)来开启方格:
PrivateSubfankai(ByValint1AsInteger,ByValint2AsInteger)
DimhangAsInteger
DimlieAsInteger
Top:
Ifint1-1=0ThenGoToBelow
IfSign(int1-1,int2)=FalseThen
Sign(int1-1,int2)=True
hang=int1-1
lie=int2
GoToDdd
EndIf
Below:
Ifint1=inthangThenGoToLeft
IfSign(int1+1,int2)=FalseThen
Sign(int1+1,int2)=True
hang=int1+1
Left:
Ifint2-1=0ThenGoToRight
IfSign(int1,int2-1)=FalseThen
Sign(int1,int2-1)=True
lie=int2-1
hang=int1
Right:
Ifint2=intlieThenGoToRighttop
IfSign(int1,int2+1)=FalseThen
Sign(int1,int2+1)=True
lie=int2+1
Righttop:
Ifint2=intlieOrint1-1=0ThenGoToLefttop
IfSign(int1-1,int2+1)=FalseThen
Sign(int1-1,int2+1)=True
Lefttop:
Ifint2=1Orint1-1=0ThenGoToLeftbelow
IfSign(int1-1,int2-1)=FalseThen
Sign(int1-1,int2-1)=True
Leftbelow:
Ifint2=1Orint1=inthangThenGoToRightbelow
IfSign(int1+1,int2-1)=FalseThen
Sign(int1+1,int2-1)=True
lie=int2-1
EndIf
Rightbelow:
Ifint2=intlieOrint1=inthangThenExitSub
IfSign(int1+1,int2+1)=FalseThen
Sign(int1+1,int2+1)=True
Else
ExitSub
Ddd:
Ifleishu(hang,lie)<
>
0Then
pic2.PaintPicturePictureClip3.GraphicCell(15-leishu(hang,lie)),(lie-1)*16,(hang-1)*16
GoToTop
pic2.PaintPicturePictureClip3.GraphicCell(15),(lie-1)*16,(hang-1)*16
Callfankai(hang,lie)
(5).“扫雷英雄榜”分3个文件夹保存(chuji,zhongji,gaoji)
Ifinthang=9Andintlie=9Then
OpenApp.Path&
\chuji.txt"
ForInputAs1
LineInput#1,str1(0)
str2(0)=CInt(Left(str1(0),InStr(str1(0),"
)))
IfintNum<
CInt(str2(0))Then
InputBox"
恭喜你破了本难度的记录!
请留下大名"
,"
无名侠"
Close1
ElseIfintlie=16Andinthang=9Then
\zhongji.txt"
LineInput#1,str1
(1)
str2
(1)=CInt(Left(str1
(1),InStr(str1
(1),"
CInt(str2
(1))Then
ElseIfintlie=30Andinthang=16Then
\gaoji.txt"
LineInput#1,str1
(2)
str2
(2)=CInt(Left(str1
(2),InStr(str1
(2),"
CInt(str2
(2))Then
(7).通过数组a()来确定插小旗,同时右上角的雷数随之改变:
先在Module1中定义数组Sign()和a():
ReDimSign(1Tointhang,1Tointlie)
ReDima(0Tointhang-1,0Tointlie-1)
然后在form1写如以下程序:
IfSign(int1+1,int2+1)=FalseThen
a(int1,int2)=a(int1,int2)+1
Ifa(int1,int2)Mod3=1Then
pic2.PaintPicturePictureClip3.GraphicCell
(1),int2*16,int1*16
k=k-1
Ifa(int1,int2)Mod3=2Then
pic2.PaintPicturePictureClip3.GraphicCell
(2),int2*16,int1*16
k=k+1
Ifa(int1,int2)Mod3=0Then
pic2.PaintPicturePictureClip3.GraphicCell(0),int2*16,int1*16
Ifk>
=0Then
imglei(0).Picture=form1.PictureClip2.GraphicCell(11-k\100)
imglei
(1).Picture=form1.PictureClip2.GraphicCell(11-k\10Mod10)
imglei
(2).Picture=form1.PictureClip2.GraphicCell(11-kMod10)
Else
imglei(0).Picture=form1.PictureClip2.GraphicCell(0)
imglei
(1).Picture=form1.PictureClip2.GraphicCell(11+k\10Mod10)
imglei
(2).Picture=form1.PictureClip2.GraphicCell(11+kMod10)
三、调试程序的过程
(1)在写程序时,刚开始自己没有想到要用标准模块来定义全局变量和过程,这样虽然也能实现功能,但增加了调试程序的难度,最后,自己试着运用标准模块来定义,果然收到不同的效果;
(2)在显示LED风格的数字时,自己想过要用LoadResPicture函数加载图片并使用PaintPicture方法绘制,而且书上也介绍了相应代码,但自己还是感觉使用PictureClip控件更方便,更容易理解,于是自己便选择了运用后者;
(3)在记录游戏成绩时文件打不开,提示信息说是类型不匹配和路径错误,自己调试了好久,现把前后的代码记录如下:
错误的代码:
Ifinthang=9andintlie=9Then
Open"
F:
str2(0)=Left(str1(0),"
EndIf
ElseIfintlie=16andinthang=16Then
str2
(1)=Left(str1
(1),"
ElseIfintlie=30andinthang=16Then
\gaojiji.txt"
str2
(2)=Left(str1
(2),"
改过的代码:
如上述课程设计的详细设计中的(5)的代码。
四、课程设计总结
可以说,这是自己编制的第一个游戏。
正如我编写电子台历一样,有种自豪的成就感,而且这种感觉越来越强烈。
扫地雷游戏在书上是属于四星级题目,应该是课程设计的题目中较难的题目。
我同样花了大量的时间来完成它。
自我感觉中,扫雷游戏的编写对自己编程的水平有着更大挑战,其中有好多的算法和技巧要求了解和掌握,不去问同学或老师,仅凭一己之力,是很难预期完成的。
在编程时的收获不少,除了对编程语言有了更深一步的了解,还有同学之间的友谊加深。
在自己有了困难时,同学或老师的大力帮助,自己真的很感动。
再一次谢谢我的同学和老师。
当然在编程时还有许多经验和教训值得反思,现在自己整理一下:
(1)在开始编程之前,要先构思各种功能实现的算法,想好了以后在上机编写,不要急于上机;
(2)编程时一定要注意变量的使用,切勿胡乱使用变量。
我在编程时候最大的问题就是变量总是搞错,那就要反复调试,最后才搞清楚变量的含义;
(3)编程不要过于复杂,多调用过程;
(4)编程结束,自己再多运行,调试几次可能有某个方面你没注意到,当然可以让同学来帮你。
五、附件
主要的源代码:
Module1:
OptionExplicit
PublicinthangAsInteger
PublicintlieAsInteger
PublicintleiAsInteger
PubliciAsInteger,jAsInteger,kAsInteger,hAsInteger
PublicintNumAsInteger
PublicarrMine()AsBoolean,colAsInteger,lnAsInteger
Publicint1AsInteger,int2AsInteger
PublicSign()AsBoolean
Publica()AsInteger
PublicSubsub1(mAsInteger,nAsInteger,lAsInteger)'
m表示行数,n表示列数,l表示雷数
Dimint3AsInteger
form1.pic2.Width=245*n'
245是一个小图片的宽度
form1.pic1.Width=245*n
form1.pic2.Height=245*m
form1.Width=340+form1.pic2.Width
form1.Height=1760+form1.pic2.Height
form1.image1.Left=form1.pic1.Width/2-375/2'
375是image1的Width属性值
form1.pic2.ScaleMode=3
Setpicf=LoadPicture("
form1.pic2.Enabled=True
form1.Timer1.Enabled=False'
开始时记时器不记时
intNum=0
inthang=m
intlie=n
intlei=l
form1.PictureClip1.Picture=LoadPicture("
form1.PictureClip2.Picture=LoadPicture("
form1.PictureClip3.Picture=LoadPicture("
form1.image1.Picture=form1.PictureClip1.GraphicCell(4)
form1.imglei(0).Picture=form1.PictureClip2.GraphicCell(11-l\100)'
得到l的百位
form1.imglei
(1).Picture=form1.PictureClip2.GraphicCell(11-l\10Mod10)'
得到l的十位
form1.imglei
(2).Picture=form1.PictureClip2.GraphicCell(11-lMod10)'
得到l的个位
Fori=0To2
form1.imgtime(i).Left=form1.pic1.Width-240-form1.imglei(Abs(i-2)).Left'
与时间显示与雷数显示对称
form1.imgtime(0).Picture=form1.PictureClip2.GraphicCell(11)
form1.imgtime
(1).Picture=form1.PictureClip2.GraphicCell(11)
form1.imgtime
(2).Picture=form1.PictureClip2.GraphicCell(11)
ReDimarrMine(inthang,intlie)
k=intlei:
h=intlei
EndSub
form1:
PrivatemAsInteger,nAsInteger
PrivateSubimage1_Click()
Callsub1(inthang,intlie,intlei)
PrivateSubImage1_MouseUp(ButtonAsInteger,ShiftAsInteger,xAsSingle,yAsSingle)
image1.Picture=PictureClip1.GraphicCell(4)
PrivateSubImage1_MouseDown(ButtonAsInteger,ShiftAsInteger,xAsSingle,yAsSingle)
image1.Picture=PictureClip1.GraphicCell(0)
imgtime(0).Picture=PictureClip2.GraphicCell(11)
imgtime
(1).Picture=PictureClip2.GraphicCell(11)
imgtime
(2).Picture=PictureClip2.GraphicCell(11)
Timer1.Enabled=False
PrivateSubend_Click()
UnloadfrmMinemain
PrivateSubForm_Load()
Callsub1(9,9,10)
PrivateSubbeginner_Click()
PrivateSubmiddle_Click()
Callsub1(16,16,40)
PrivateSubrefer_Click()
Loadf
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 扫雷 程序设计 报告