扫雷
演示如何实现概率的分配
Form1 里画一个 CommandButton
名称cmdMine ,Caption属性清空
Height 设为255, Width设为255
Index属性设为0
使用如下代码:
Option Explicit Private bGameOver As Boolean Private Sub cmdMine_Click(Index As Integer) If bGameOver Then Exit Sub Static c As Integer If cmdMine(Index).Tag = "1" Then MsgBox "你踩到地雷了死米嘎!" bGameOver = True Else cmdMine(Index).Visible = False c = c + 1 End If Me.Caption = "已经探测:" & CStr(c) & "个!" End Sub Private Sub Form_Load() Dim i As Integer,j As Integer,k As Integer Dim s As String InputHeight: s = InputBox("请输入雷区的高度(10 - 100):","20") If CInt(s) < 10 Or CInt(s) > 100 Then MsgBox "请输入正确的数值!",vbCritical GoTo InputHeight End If i = CInt(s) InputWidth: s = InputBox("请输入雷区的宽度(10 - 100):",vbCritical GoTo InputWidth End If j = CInt(s) Me.Height = 240 + i * (375) '255 + 120 Me.Width = 240 + j * (375) For k = 1 To i * j - 1 Load cmdMine(k) If k Mod j Then cmdMine(k).Left = cmdMine(k - 1).Left + 375 If k >= j Then cmdMine(k).Top = cmdMine(k - j).Top + 375 cmdMine(k).Visible = True Next k InputPosible: s = InputBox("请输入雷区概率(1 - 99):","20") If CInt(s) < 1 Or CInt(s) > 99 Then MsgBox "请输入正确的概率!",vbCritical GoTo InputPosible End If k = CInt(s) For i = 0 To cmdMine.UBound j = CInt(Rnd * 100) If j <= k Then cmdMine(i).Tag = "1" Else cmdMine(i).Tag = "0" Next i End Sub
给想设计小游戏的菜鸟 很菜很菜很菜很菜很菜很菜很菜很菜很菜,比吃菜的小鸟还菜的菜鸟