Advertisement
Tony041010

踩地雷MineSweeper

Jul 15th, 2021
631
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Dim a(100) As Integer  '第23-3題回放才用的到
  2. Dim Place(8) As Integer
  3. '第一題,計算炸彈數,邊界問題可以忽略
  4. '炸彈的tag已經標示成1,共有10顆
  5. Private Sub Command1_Click(index As Integer)
  6.     If Command1(index).Tag = "1" Then
  7.    
  8.         Command1(index).Picture = Image1.Picture
  9.         MsgBox "boom!!!"
  10.     Else
  11.    
  12.         If Command1(index).Caption = "" Then
  13.             Label1 = Label1 + 1
  14.             If Label1.Caption = 90 Then
  15.                 MsgBox "you win"
  16.             End If
  17.         End If
  18.        
  19.         a(Label1) = index
  20.         BFS (index)
  21.        
  22.     End If
  23.    
  24. End Sub
  25.  
  26. '第二題,地雷紅旗標示
  27. 'button會傳回滑鼠狀態,1表示左鍵,2表右鍵,4表中鍵
  28. 'image2是旗子,image3是空白圖
  29. '按第一下插旗,按第二下收回旗子
  30. Private Sub Command1_MouseDown(index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
  31.     '第三題,已經翻開不要插旗
  32.    If Command1(index).Caption = "" Then
  33.         If Button = 2 Then
  34.             If Command1(index).Picture = Image3.Picture Then
  35.                 Command1(index).Picture = Image2.Picture
  36.             Else
  37.                 Command1(index).Picture = Image3.Picture
  38.             End If
  39.         End If
  40.     Else
  41.         Command1(index).Picture = Image3.Picture
  42.     End If
  43.    
  44.    
  45. End Sub
  46. '第四題,解邊界問題
  47.  
  48.  
  49. '以下勿動,埋入10個地雷方便你第一題測試
  50. Private Sub Command2_Click()
  51.     Label1.Caption = 0
  52.    
  53.     For i = 0 To 143
  54.         Command1(i).Tag = ""
  55.         Command1(i).Caption = ""
  56.         Command1(i).Picture = Image3.Picture
  57.     Next
  58.    
  59.     Randomize
  60.    
  61.     n = 0
  62.    
  63.     Do
  64.    
  65.         X = Int(Rnd * 144)
  66.        
  67.         If Command1(X).Tag = "" And Command1(X).Visible = True Then
  68.             n = n + 1
  69.             Command1(X).Tag = "1"
  70.             'Command1(X).Caption = n
  71.        End If
  72.    
  73.     Loop Until n = 10
  74. End Sub
  75.  
  76. Private Sub Command3_Click()
  77.     Timer1.Interval = 500
  78.     Label3 = 0
  79.     Label2 = Label1
  80.     If Int(Label3) > Int(Label2) Then
  81.         Timer1.Interval = 0
  82.     End If
  83. End Sub
  84.  
  85.  
  86. Private Sub Timer1_Timer()
  87.     If Int(Label3) <= Int(Label2) Then
  88.         Command1_Click (a(Label3))
  89.         Label3 = Label3 + 1
  90.     End If
  91. End Sub
  92.  
  93. '第4題,1.完成BFS的最後一個if
  94. '2.你要修改Command1_Click裡面某段,而且會用到BFS ?????
  95. Private Sub BFS(index As Integer)
  96.     If Command1(index).Visible = True And Command1(index).Caption = "" Then
  97.         If Command1(index).Caption = "" Then
  98.             Label1.Caption = Label1.Caption + 1
  99.             If Label1.Caption = 90 Then
  100.                 MsgBox "you win"
  101.             End If
  102.         End If
  103.         a(Label1) = index
  104.         Command1(index).Caption = 0
  105.         Command1(index).Picture = Image3.Picture
  106.         If Command1(index - 13).Tag = "1" Then
  107.             Command1(index).Caption = Command1(index).Caption + 1
  108.         End If
  109.         If Command1(index - 12).Tag = "1" Then
  110.             Command1(index).Caption = Command1(index).Caption + 1
  111.         End If
  112.         If Command1(index - 11).Tag = "1" Then
  113.             Command1(index).Caption = Command1(index).Caption + 1
  114.         End If
  115.         If Command1(index - 1).Tag = "1" Then
  116.             Command1(index).Caption = Command1(index).Caption + 1
  117.         End If
  118.         If Command1(index + 1).Tag = "1" Then
  119.             Command1(index).Caption = Command1(index).Caption + 1
  120.         End If
  121.         If Command1(index + 11).Tag = "1" Then
  122.             Command1(index).Caption = Command1(index).Caption + 1
  123.         End If
  124.         If Command1(index + 12).Tag = "1" Then
  125.             Command1(index).Caption = Command1(index).Caption + 1
  126.         End If
  127.         If Command1(index + 13).Tag = "1" Then
  128.             Command1(index).Caption = Command1(index).Caption + 1
  129.         End If
  130.    
  131.         '*********4-1開始
  132.                          
  133.         If Command1(index).Caption = 0 Then
  134.             BFS index - 13
  135.             BFS index - 12
  136.             BFS index - 11
  137.             BFS index - 1
  138.             BFS index + 1
  139.             BFS index + 11
  140.             BFS index + 12
  141.             BFS index + 13
  142.  
  143.             '*********4-1結束,接著你要修改Command1_Click裡面某段,而且會用到BFS ?????
  144.        End If
  145.     End If
  146. End Sub
  147.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement