没有合适的资源?快使用搜索试试~ 我知道了~
VB模拟扫雷游戏.doc
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 154 浏览量
2022-06-26
10:04:42
上传
评论
收藏 630KB DOC 举报
温馨提示
试读
22页
VB模拟扫雷游戏.doc
资源推荐
资源详情
资源评论
VB 模拟扫雷游戏的尝试
一、 编程目的
那天老师展示了一个不完全的扫雷,激发了编程欲望,于是写了扫雷来练练手。
二、 编程思路
1、 新建 command_up 和 label_down,本来要用 text_down,但是后来在左右键同时按
下的时候与 TextBox 的 enable 冲突,于是改成 label。
2、 用 load 加载控件
3、 根据雷区的 X、Y、以及难度进行随机布雷。
4、 统计每一个 label 周围雷的数量并作为 label 的 caption。
5、 在单击 command 的时候显示 label
6、 在右击 command 的时候进行标记
7、 在 label 上左右键同时按下的时候检查已标记雷的数量与 label 显示的数量是否一致。
三、 界面设计
四、 代码设计
Dim Start_Time, End_Time
Dim Area_X%, Area_Y%, Area%, Area_List()
Dim Current_Mine%
Dim Difficulty#
Dim Continue_Flag%, Success_Flag%, LeftAndRight_Flag%
Dim Near_List
Dim Mine_Count
Private Sub Command_End_Click()
End
End Sub
Private Sub Delete_Item(List(), Index As Integer)
Dim i%
For i = LBound(List) + Index - 1 To UBound(List) - 1
List(i) = List(i + 1)
Next i
'防止 100%的困难度
If UBound(List) > LBound(List) Then ReDim Preserve List(LBound(List) To UBound(List) -
1)
End Sub
Private Sub Command_retry_Click()
'卸载
For i = 1 To Area
Unload Label_Down(i)
Unload Command_Up(i)
Next i
Command_Start.Caption = "开始游戏"
Call Command_Start_Click
End Sub
Private Sub Command_Up_Click(Index As Integer)
Success_Flag = 1
If Continue_Flag = 1 Then
If Timer1.Enabled = False Then Call Command_Start_Click
If Label_Down(Index).Caption = "X" Then
Success_Flag = 0
Continue_Flag = 0
For i = 1 To Area
If Command_Up(i).Visible = True And Command_Up(i).Caption = "X" And
Label_Down(i).BackColor = vbRed Then
'标记雷正确
Command_Up(i).Picture = LoadPicture(App.Path + "\pictures\mine_correct.gif", , ,
Command_Up(i).Width, Command_Up(i).Height)
Command_Up(i).Visible = True
Label_Down(i).Visible = True
ElseIf Command_Up(i).Visible = True And Command_Up(i).Caption = "X" And
Label_Down(i).BackColor = vbGreen Then
'标记雷错误
Command_Up(i).Picture = LoadPicture(App.Path + "\pictures\mine_wrong.gif", , ,
Command_Up(i).Width, Command_Up(i).Height)
Command_Up(i).Visible = True
Label_Down(i).Visible = True
Else
Command_Up(i).Visible = False
Label_Down(i).Visible = True
End If
Next i
Timer1.Enabled = False
temp = MsgBox("Game Over !", vbOKOnly, "游戏结束")
ElseIf Val(Label_Down(Index).Caption) > 0 Then
Command_Up(Index).Visible = False
Label_Down(Index).Visible = True
Else
'如果等于 0 的话应该将周边的清零
Command_Up(Index).Visible = False
Label_Down(Index).Visible = True
j = Index
For i = 1 To 8
'判断控件是否存在
If j + Near_List(i) > 0 And j + Near_List(i) <= Area Then
'判断是否相邻
If Abs(Label_Down(j + Near_List(i)).Left - Label_Down(j).Left) <=
Label_Down(j).Width And Abs(Label_Down(j + Near_List(i)).Top - Label_Down(j).Top) <=
Label_Down(j).Height Then
'判断是否有雷
If Label_Down(j + Near_List(i)).BackColor = vbGreen And Command_Up(j +
Near_List(i)).Visible = True Then
Call Command_Up_Click(j + Near_List(i)) '注意此处循环调用的时候一定
要避免陷入死循环
End If
End If
End If
Next i
End If
'检查是否游戏成功
For i = 1 To Area
If Command_Up(i).Visible = True And Label_Down(i).Caption <> "X" Then
Success_Flag = 0
Exit For
End If
Next i
If Success_Flag = 1 Then
If Continue_Flag = 1 Then
Timer1.Enabled = False
For i = 1 To Area
If Command_Up(i).Visible = True And Command_Up(i).Caption = "X" And
Label_Down(i).BackColor = vbRed Then
'标记雷正确
Command_Up(i).Picture = LoadPicture(App.Path + "\pictures\mine_correct.gif", , ,
Command_Up(i).Width, Command_Up(i).Height)
Command_Up(i).Visible = True
Label_Down(i).Visible = True
ElseIf Command_Up(i).Visible = True And Command_Up(i).Caption = "X" And
Label_Down(i).BackColor = vbGreen Then
'标记雷错误
Command_Up(i).Picture = LoadPicture(App.Path + "\pictures\mine_wrong.gif", , ,
Command_Up(i).Width, Command_Up(i).Height)
Command_Up(i).Visible = True
Label_Down(i).Visible = True
Else
Command_Up(i).Visible = False
Label_Down(i).Visible = True
End If
Next i
temp = MsgBox(" 恭 喜 , 扫 雷 成 功 ! " & vbCrLf & " 耗 时 : " &
Mid(Label_Time.Caption, 4) & vbCrLf & "鸣谢:平方 X O(∩_∩)O~", vbOKOnly, "成功")
End If
Continue_Flag = 0 '提示一次后结束,防止在调用 Command_Click 事件中重复提示
End If
End If
Command_Start.SetFocus
End Sub
Private Sub Command_Start_Click()
If Command_Start.Caption = "开始游戏" Then
Command_Start.Caption = "重新开始"
Continue_Flag = 1
Timer1.Enabled = True
Difficulty = Val(Text_Difficulty.Text) / 100
Area_X = Val(Text_X.Text)
Area_Y = Val(Text_Y.Text)
Area = Area_X * Area_Y
'初始化这里进行二次初始化的原因是如果在之前的运行中对字体进行了改变,将有可
能造成此处的控件大小发生变化
With Picture_show
.Left = 200
.Top = 200
.Width = 750 * 10
.Height = 750 * 10
.Visible = False
End With
With Command_Up(0)
.Left = Picture_show.Left
.Top = Picture_show.Top
.Width = Picture_show.Width / 10
.Height = Picture_show.Height / 10
.FontSize = 1 '防止自动缩放
.Visible = False
End With
With Label_Down(0)
.Left = Picture_show.Left
.Top = Picture_show.Top
.Width = Picture_show.Width / 10
.Height = Picture_show.Height / 10
.FontSize = 1 '防止自动缩放
.Visible = False
End With
With Label_Down(0)
.Left = 200
.Top = 200
.Width = 750 * 10 / IIf(Area_X > Area_Y, Area_X, Area_Y)
.FontSize = 25 * (.Width / 750) '会自动缩放,必须先设置了
.Height = 750 * 10 / IIf(Area_X > Area_Y, Area_X, Area_Y)
.Visible = False
End With
With Command_Up(0)
.Left = 200
.Top = 200
.Width = Label_Down(0).Width
.Height = Label_Down(0).Height
.Visible = False
End With
ReDim Near_List(1 To 8)
Near_List(1) = 0 - 1 - Area_Y
Near_List(2) = 0 - 0 - Area_Y
Near_List(3) = 0 + 1 - Area_Y
Near_List(4) = 0 - 1
剩余21页未读,继续阅读
资源评论
智慧安全方案
- 粉丝: 3652
- 资源: 59万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 详解protobuf-c之在C语言中如何使用repeated生成数组和字符串(包含配置pb-callback-t)
- Python 程序语言设计模式思路-并发模式:消费者模式:协调生产者和消费者之间的数据交换
- pythonA*算法(A-star algorithm),寻路算法
- guitest.zip
- udp_echo.v
- udp_echo_server.v
- python双向广度优先搜索算法(Bidirectional Breadth-First Search, BBFS),寻路算法
- python迭代加深算法(Iterative Deepening Depth-First Search, IDDFS),寻路算法
- 京东商品链接采集助手 2024版
- 基于Java的ApplicationPower快速项目生成脚手架设计源码
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功