文件名称:VB的的的的的的扫雷
文件大小:36KB
文件格式:EXE
更新时间:2011-12-18 05:11:36
123
Dim b As Single Dim a(9, 9) As Integer Dim b1(9, 9) As Integer Dim b2(9, 9) As Integer Dim cmd(9, 9) As CommandButton Dim lab(9, 9) As Label Private Sub Command1_Click(Index As Integer) x = Index: i = x \ 10: j = x Mod 10 If a(i, j) = 1 Then Call baozha ElseIf leishu(i, j) = 0 Then Call fan(i, j) Else cmd(i, j).Visible = False End If End Sub Private Sub Command1_MouseDown(Index As Integer, Button As Integer, Shift As Integer, x As Single, y As Single) If Button = 2 Then n = Index: i = n \ 10: j = n Mod 10 If cmd(i, j).Caption = "?" Then cmd(i, j).Caption = "" Me.Tag = Me.Tag + 1: Text1.Text = Me.Tag If a(i, j) = 1 Then b1(i, j) = 1 Else cmd(i, j).Caption = "?" Me.Tag = Me.Tag - 1: Text1.Text = Me.Tag End If End If If Me.Tag = 0 Then Call jianyan End Sub Private Sub Command2_Click() Picture1.Enabled = True For i = 0 To 9 For j = 0 To 9 a(i, j) = 0 cmd(i, j).Visible = True cmd(i, j).Caption = "" Next Next Call bulei(b) End Sub Private Sub Command3_Click() b = 10 Picture1.Enabled = True For i = 0 To 9 For j = 0 To 9 a(i, j) = 0 cmd(i, j).Visible = True cmd(i, j).Caption = "" Next Next b = 10 Call bulei(b) End Sub Private Sub Command4_Click() b = 10 Picture1.Enabled = True For i = 0 To 9 For j = 0 To 9 a(i, j) = 0 cmd(i, j).Visible = True cmd(i, j).Caption = "" Next Next b = 15 Call bulei(b) End Sub Private Sub Command5_Click() b = 10 Picture1.Enabled = True For i = 0 To 9 For j = 0 To 9 a(i, j) = 0 cmd(i, j).Visible = True cmd(i, j).Caption = "" Next Next b = 20 Call bulei(b) End Sub Private Sub Form_Load() b = 10 Picture1.Move 0, 0 Picture1.Height = (Command1(0).Height + 5) * 10 + 3 Picture1.Width = (Command1(0).Height + 5) * 10 + 3 Me.Height = Picture1.Height + 560 Me.Width = Picture1.Width + Frame1.Width + 260 Label1(0).Move 0, 0 Command1(0).Move 0, 0 Frame1.Move Picture1.Width + 60, 650 Command3.Move Picture1.Width + 80, 100 Command4.Move Picture1.Width + 180 + 375, 100 Command5.Move Picture1.Width + 280 + 750, 100 Set lab(0, 0) = Label1(0) Set cmd(0, 0) = Command1(0) For n = 1 To 99 i = n \ 10: j = n Mod 10 Load Label1(n) Set lab(i, j) = Label1(n) Load Command1(n) Set cmd(i, j) = Command1(n) With lab(i, j) .Left = 5 + j * lab(0, 0).Width .Top = 5 + i * lab(0, 0).Height .Visible = True End With With cmd(i, j) .Left = 5 + j * cmd(0, 0).Width .Top = 5 + i * cmd(0, 0).Height .Visible = True End With Next Call bulei(b) End Sub Private Sub bulei(b) Dim i, j, k As Integer Randomize For n = 1 To b k = Int(Rnd * (100 - n)) + 1 i = k \ 10: j = k Mod 10 Do While a(i, j) = 1 k = Int(Rnd * (100 - n)) + 1 i = k \ 10: j = k Mod 10 Loop a(i, j) = 1: b1(i, j) = 1 Next For i = 0 To 9 For j = 0 To 9 b2(i, j) = leishu(i, j) Select Case b2(i, j) Case 1 lab(i, j).ForeColor = RGB(0, 0, 255) Case 2 lab(i, j).ForeColor = RGB(255, 0, 0) Case 3 lab(i, j).ForeColor = RGB(0, 127, 0) Case 4 lab(i, j).ForeColor = RGB(0, 255, 255) Case 5 lab(i, j).ForeColor = RGB(255, 255, 0) Case Else lab(i, j).ForeColor = RGB(255, 0, 255) End Select lab(i, j).Caption = IIf(b2(i, j) = 0, "", b2(i, j)) Next Next Label2.Caption = "游戏开始" Me.Tag = b: Text1.Text = b End Sub Private Function leishu(x, y) k = 0 For i = IIf(x = 0, 0, x - 1) To IIf(x = 9, 9, x + 1) For j = IIf(y = 0, 0, y - 1) To IIf(y = 9, 9, y + 1) k = k + a(i, j) Next Next leishu = k End Function Private Sub baozha() For i = 0 To 9 For j = 0 To 9 If a(i, j) = 1 Then cmd(i, j).Caption = "!" Next Next Picture1.Enabled = False Label2.Caption = "你输了!" End Sub Private Sub jianyan() For i = 0 To 9 For j = 0 To 9 If a(i, j) = 1 And cmd(i, j).Caption = "" Then Exit Sub If cmd(i, j).Caption = "" Then cmd(i, j).Visible = False Next Next Picture1.Enabled = False Label2.Caption = "你赢了!" End Sub Private Sub fan(x, y) For i = IIf(x = 0, 0, x - 1) To IIf(x = 9, 9, x + 1) For j = IIf(y = 0, 0, y - 1) To IIf(y = 9, 9, y + 1) If cmd(i, j).Visible = True Then cmd(i, j).Visible = False If leishu(i, j) = 0 Then Call fan(i, j) End If Next Next End Sub