傻大方


首页 > 学习 >

VB|VB扫雷小游戏编程代码



按关键词阅读: 编程 代码 VB 小游戏 扫雷

1、VB扫雷小游戏一. 编程目的二. 编程思路1. 新建 command_up 和 label_down 控件2. 用load加载控件3. 根据雷区的X、Y、以及难度进行随机布雷 。
4. 统讣每一个label周由雷的数疑并作为label的caption5. 在单击command的时候显示label6. 在右击command的时候进行标记7. 在label上左右键同时按下的时候检查已标记雷的数量与label显示的数量是否一致 。
三. 界而设计四代码设计Dim Start_Timez End_TimeDim Area_X%z Area_Y%z Area%, Area_List()Dim Current_M 。

【VB|VB扫雷小游戏编程代码】2、ine%Dim Difficulty#Dim Continue_Flag%;
Success_Flag%, LeftAndRight_Flag%Dim Near_ListDim Mine_CountPrivate Sub Command_End_Click()EndEnd SubPrivate Sub Delete_ltem(List(), Index As Integer)Dimi%For i = LBound(List) + Index -1 To UBound(List) -1List(i) = List(i + 1)Next i防止100%的困难度If UBound(List) LBo 。

3、und(List) Then ReDim Preserve List(LBound(List) To UBound(List) -1)End SubPrivate Sub Command_retry_Click()啣载For i = 1 To AreaUn load Label_Down(i)Un load Comma nd_Up(i)Next iCommand_Start.Caption = ”开始游戏Call Command_Start_ClickEnd SubPrivate Sub Command_Up_Click(lndex As Integer)Success_Flag = 1If。

4、Continue_Flag = 1 ThenIf Timerl.Enabled = False Then Call Command_Start_ClickIf Label_Down(lndex).Caption = X ThenSuccess_Flag = 0Continue_Flag = 0For i = 1 To AreaIf Command_Up(i).Visible = True And Command_Up(i).Caption = X AndLabel_Down(i).BackColor = vbRed Then标记雷正确Command_Up(i).Picture=LoadPict 。

5、ure(App.Path+,picturesmine_correct.gif,/ 八 Command_Up(i).Width, Command_Up(i)Height)Command_Up(i).Visible = TrueLabel_Down(i).Visible = TrueElself Command_Up(i).Visible = True And Command_Up(i).Caption = X AndLabel_Down(i).BackColor = vbGreen Then标记雷错误Command_Up(i).Picture=LoadPicture(App.Path+,pict 。

6、uresmine_wrong.gif,/., Command_Up(i)Width, Command_Up(i).Height)Command_Up(i).Visible = TrueLabel_Down(i).Visible = TrueElseCommand_Up(i).Visible = FalseLabel_Down(i).Visible = TrueEnd IfNext iTimerl.Enabled = Falsetemp = MsgBox(uGame OvervbOKOnly,游戏结束)Elself Val(Label_Down(lndex).Caption) 0 ThenCom 。

7、ma nd_Up(l ndex).Visible = FalseLabel_Down(lndex).Visible = TrueElse如果等于0的话应该将周边的淸零Command_Up(l ndex).Visible = FalseLabel_Down(lndex).Visible = Truej = IndexFor i = 1 To 8判断控件是否存在If j + Near_List(i) 0 And j + Near_List(i) X11 ThenSuccess_Flag 二 0Exit ForEnd IfNext iIf Success_Flag = 1 ThenIf Contin 。

8、ue_Flag = 1 ThenTimerl.E nabled = FalseFor i = 1 To AreaIf Command_Up(i).Visible = True And Command_Up(i).Caption = X AndLabel_Down(i).BackColor = vbRed Then标记雷正确Command_Up(i).Picture=LoadPicture(App.Path+,picturesmine_correct.gif,/ 八 Command_Up(i)Width, Command_Up(i).Height)Command_Up(i).Visible =。

9、TrueLabel_Down(i)Visible = TrueElself 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+picturesmine_wrong.gif: , Command_Up(i)Width , Command_Up(i)Height)Command_Up(i).Visible = TrueLabel_Down(i).Visibl 。

10、e = TrueElseCommand_Up(i).Visible = FalseLabel_Down(i).Visible = TrueEnd IfNext itemp = MsgBox(u 恭喜 , 扫雷 成功! & vbCrLf & ” 耗时:11 &Mid(LabeLTime.Caption/ 4) & vbCrLf & ”鸣谢:平方 X 0()OvbOKOnly, ”成功“)End IfContinue_Flag二0 提示一次后结束 , 防止在调用Command_Click事件中重复提 示End IfEnd IfCommand_Start.SetFocusEnd SubPrivate Sub 。

11、 Command_Start_Click()If Command_Start.Caption =开始游戏” ThenCommand_Start.Caption =重新开始”Contin ue_Flag = 1Timerl.Enabled = TrueDifficulty = Val(Text_Difficulty.Text) / 100Area_X = Val(Text_X.Text)AreaY = Val(TextY.Text)Area = Area_X * Area_Y初始化这里进行二次初始化的原因是如果在之前的运行中对字体进行了改变 , 将 有可能造成此处的控件大小发生变化With Pict 。

12、ure_showLeft = 200.Top = 200.Width = 750 * 10Height = 750 10.Visible = FalseEnd WithWith Command_Up(0) Left = Pictureshow.Left.Top = Picture_show.Top.Width = Picture_show.Width / 10.Height = Picture_show. Height / 10.FontSize = 1防止自动缩放.Visible = FalseEnd WithWith Label_Down(0) Left = Picture_show.Le 。

13、ft.Top = Picture__show.Top.Width = Picture_show.Width / 10.Height = Picture_show. Height / 10.FontSize = 1防止自动缩放.Visible = FalseEnd WithWith Label_Down(0)Left = 200.Top = 200.Width = 750 * 10 / llf(Area_X AreaX AreaX, AreaY).FontSize = 25 * (.Width / 750)会自动缩放 , 必须先设宜了 .Height = 750 * 10/ llf(Area_X A 。

14、rea_Y Area_Xz Area_Y) .Visible = FalseEnd WithWith Command_Up(0)Left = 200.Top = 200.Width = Label_Down(0).Width.Height = Label_Down(0).Height.Visible = FalseEnd WithReDim Near_List(l To 8)NearList(l) = 0-l-Area_YNear_List(2) = 0-0-Area_YNear_List(3) = 0 + 1- Area_YNear_List(4) = 0-1Near_List(5) = 0 。

15、 + 1Near_List(6) = 0 1 + Area_YNear_List(7) = 0-0 +Area_YNear_List(8) = 0 + l + AreaY如果在列表中有相等的元素将有可能造成统汁雷的数目错误For i = 1 To 8Forj = i + lTo8If Near_List(i) = Near_List(j) Then Near_List(i) = 0 Next jNext iArea_temp = 0ForY = lToArea-Y加载labelFor X = 1 To Area_XArea_temp = Area_temp + 1Load Label_Down 。

16、(Area_temp)With Label_Down(Area_temp)丄eft = Label_Down(0).Left + Label_Down(0)Width * (Area_temp 1) Mod Area_Y).Top = Label_Down(0).Top + Label_Down(0).Height * (Area_temp - l)AreaY) BackColor = vbGreen.Visible = FalseAlign ment = 2Font = .FontBoldEnd With加1 载 commandLoad Command_Up(Area_tGmp)With C 。

17、ommand_Up(Area_temp)对列数求余的话就是在这一行第几个了Left = Command_Up(0).Left + Command_Up(0).Width (Area_tmp 1) Mod Area_Y)整除列数的话可以确定第几行.Top = Command_Up(0).Top + Command_Up(0).Height * (Area_temp 1) Area_Y).Visible = TrueEnd WithNextXNext YReDim Area__List(l To Area)For i = 1 To AreaArea_List(i) = iNext i随即布雷Ran 。

18、domizeMine_Count = Va I (Text_M i n e_Co u nt .Text)For i = 1 To Mine_CountCurrent_Mine = lnt(Rnd * (UBound(Area_List) - LBound(Area_List) + 1) + 1)在数 组中随机一个 , 注意此处2个+1的必要性和准确性Label_Down(Area_List(CuiTent_Mine).BackColor = vbRed 将该位置标记为雷Call DeleteJtemfAreaList, Current_Mine) 除该位防止再次标记Next i检查雷的数目For。

19、j = 1 To AreaIf Label_Down(j).BackColor = vbRed ThenLabel_Down(j).Caption = nXHElseMine_Number = 0For i = 1 To 8判断控件是否存在If j + Near_List(i) 0 And j + Near_List(i) 0 And Index + Near_List(i) X AndCommand_Up(lndex + Near_List(i).Caption 0 And Index + Near_List(i) 0 And Index + Near_List(i) X” ThenCall 。

20、 Command_Up_Click(lndex + Near_List(i)End IfEnd IfEnd IfNext iElse 如果没有全部标注的话应该显示一下嘛For i = 1 To 8判断控件是否存在If Index + Near_List(i) 0 And Index + Near_List(i) X” ThenCommand_Up(lndex + Near_List(i).Picture = LoadPicture(App.Path +”picturesxia.gi 化z , Command_Up(lndex)Width,Comma nd_Up(lndex)Height)End 。

21、 IfEnd IfEnd IfNext iEnd IfElseLeftAndRight_Flag = ButtonPrint LeftAndRight_FIagEnd IfEnd SubPrivate Sub Timerl_Timer()LeftAndRight_Flag = 0End_Time = Now()spend_time = (End_Time - Start_Time) * 10 A 5Label_Time.Caption =时间:” & Format(lnt(spend_time) (60 * 60) , ”00”)& : & Format(lnt(spend_time) Mod (60 * 60) 60, ”00) & : & Format(lnt(spend_time) Mod 60, OO) & Format(lnt(spend_time - lnt(spend_time) * 1000), 000)End Sub五.软件截图卜2金1o2H-*2h*1o21*1*o_AooozxoOoooOoooooooo*h*1ooooo28o4*o21ooOo*I_iMhoO121IalaBwI-H3KXSB - 8 8 二 。


    稿源:(未知)

    【傻大方】网址:/a/2021/0816/0023746889.html

    标题:VB|VB扫雷小游戏编程代码


    上一篇:寿星|小寿星生日致辞精选

    下一篇:2020|2020年教育扶贫简报