Advertisement
Tony041010

俄羅斯方塊Teris

Jul 15th, 2021
959
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Dim nowXY As Integer  '紀錄方塊現在位置
  2. Dim brk  '紀錄方塊樣式
  3. Dim brkcolor  '紀錄方塊顏色
  4. Dim bridx As Integer  '亂數產生方塊
  5. Private Function 移動(f As Integer, t As Integer)
  6.     For i = 3 To 0 Step -1
  7.         For j = 3 To 0 Step -1
  8.             If Command1(4 * i + j).BackColor <> &H8000000F Then
  9.                 Command4(f + 10 * i + j).BackColor = &H8000000F
  10.             End If
  11.         Next
  12.     Next
  13.    
  14.     collision = False
  15.     For i = 3 To 0 Step -1
  16.         For j = 3 To 0 Step -1
  17.             If Command1(i * 4 + j).BackColor <> &H8000000F Then
  18.                 If Command4(t + i * 10 + j).BackColor <> &H8000000F Then
  19.                     collision = True
  20.                 End If
  21.             End If
  22.         Next
  23.     Next
  24.    
  25.     If collision = True Then
  26.      a = f
  27.      Else
  28.      a = t
  29.     End If
  30.    
  31.     For i = 3 To 0 Step -1
  32.         For j = 3 To 0 Step -1
  33.             If Command1(i * 4 + j).BackColor <> &H8000000F Then
  34.                     Command4(a + i * 10 + j).BackColor = Command1(i * 4 + j).BackColor
  35.             End If
  36.         Next
  37.     Next
  38.     nowXY = a
  39.     移動 = Not collision
  40. End Function
  41.  
  42. Private Sub Command3_Click()
  43.     a = Array(12, 8, 4, 0, 13, 9, 5, 1, 14, 10, 6, 2, 15, 11, 7, 3)
  44.     For i = 0 To 15
  45.         Command2(i).BackColor = Command1(a(i)).BackColor
  46.     Next
  47.     For i = 0 To 15
  48.         Command1(i).BackColor = Command2(i).BackColor
  49.     Next
  50.  
  51. End Sub
  52. Private Function 旋轉(f As Integer)
  53.     For i = 3 To 0 Step -1
  54.         For j = 3 To 0 Step -1
  55.             If Command1(i * 4 + j).BackColor <> &H8000000F Then
  56.                 Command4(f + i * 10 + j).BackColor = &H8000000F
  57.             End If
  58.         Next
  59.     Next
  60.    
  61.     Command3_Click
  62.     collision = False
  63.     For i = 3 To 0 Step -1
  64.         For j = 3 To 0 Step -1
  65.             If Command1(i * 4 + j).BackColor <> &H8000000F Then
  66.                 If Command4(f + i * 10 + j).BackColor <> &H8000000F Then
  67.                     collision = True
  68.                 End If
  69.             End If
  70.         Next
  71.     Next
  72.    
  73.     If collision = True Then
  74.      Command3_Click
  75.      Command3_Click
  76.      Command3_Click
  77.     End If
  78.     a = f
  79.     For i = 3 To 0 Step -1
  80.         For j = 3 To 0 Step -1
  81.             If Command1(i * 4 + j).BackColor <> &H8000000F Then
  82.                     Command4(a + i * 10 + j).BackColor = Command1(i * 4 + j).BackColor
  83.             End If
  84.         Next
  85.     Next
  86.     nowXY = a
  87. End Function
  88. Private Sub Timer1_Timer()
  89.     If Not 移動(nowXY, nowXY + 10) Then
  90.         For i = 3 To 0 Step -1
  91.             For j = 3 To 0 Step -1
  92.                 If Command1(i * 4 + j).BackColor <> &H8000000F Then
  93.                     a = Int((nowXY + i * 10 + j) / 10) * 10 + 8
  94.                     Print a
  95.                    
  96.                     Do
  97.                         eliminate = True
  98.                         For k = a To a - 7 Step -1
  99.                             If Command4(k).BackColor = &H8000000F Then
  100.                                 eliminate = False
  101.                             End If
  102.                         Next
  103.                         If eliminate = True Then
  104.                             For k = a To 11 Step -1
  105.                                 Command4(k).BackColor = Command4(k - 10).BackColor
  106.                             Next
  107.                         Else
  108.                             Exit Do
  109.                         End If
  110.                     Loop
  111.                 End If
  112.             Next
  113.         Next
  114.         If nowXY < 10 Then
  115.        
  116.         Timer1.Interval = 0
  117.         MsgBox "Game Over"
  118.         Else
  119.             nowXY = 3
  120.             bridx = Int(Rnd * 7)
  121.             Text1.Text = brk(bridx)
  122.         End If
  123.     End If
  124. End Sub
  125.  
  126.  
  127. Private Sub Command5_Click()
  128.     Timer1.Interval = 500
  129.     For i = 1 To 199
  130.         Command4(i).BackColor = &H8000000F
  131.         If i Mod 10 = 0 Or i Mod 10 = 9 Or i >= 190 Then
  132.             Command4(i).BackColor = vbBlack
  133.             Command4(i).Picture = Image1.Picture
  134.         End If
  135.     Next
  136.     nowXY = 3
  137.     bridx = Int(Rnd * 7)
  138.     Text1.Text = brk(bridx)
  139.     移動 3, 3
  140.     Picture1.SetFocus
  141. End Sub
  142. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
  143.     If KeyCode = vbKeyLeft Then
  144.         移動 nowXY, nowXY - 1
  145.     ElseIf KeyCode = vbKeyRight Then
  146.         移動 nowXY, nowXY + 1
  147.     ElseIf KeyCode = vbKeyUp Then
  148.         旋轉 nowXY
  149.     ElseIf KeyCode = vbKeyDown Then
  150.         移動 nowXY, nowXY + 10
  151.     End If
  152. End Sub
  153.  
  154.  
  155. '第一題,畫面初始
  156. Private Sub Form_Load()
  157.     For i = 1 To 199
  158.         Load Command4(i)
  159.         If i Mod 10 = 0 Then
  160.             Command4(i).Left = Command4(i - 10).Left
  161.             Command4(i).Top = Command4(i - 1).Top + Command4(i - 10).Height
  162.         Else
  163.             Command4(i).Left = Command4(i - 1).Left + Command4(i - 1).Width
  164.             Command4(i).Top = Command4(i - 1).Top
  165.         End If
  166.        
  167.         If i Mod 10 = 0 Or i Mod 10 = 9 Or i >= 190 Then
  168.             Command4(i).BackColor = vbBlack
  169.             Command4(i).Picture = Image1.Picture
  170.         End If
  171.         Command4(i).Visible = True
  172.     Next
  173.     Command4(0).BackColor = vbBlack
  174.     Command4(0).Picture = Image1.Picture
  175.     brk = Array("0000001001110000", "0000001101100000", "0000011001100000", "0000111100000000", "0000011000110000", "0000011100010000", "0000011101000000")
  176.     List1.Clear
  177.     For i = 0 To UBound(brk)
  178.         List1.AddItem brk(i)
  179.     Next
  180.    
  181.     brkcolor = Array(vbBlue, vbCyan, vbGreen, vbMagenta, vbRed, &HFFC0C0, vbYellow)
  182. End Sub
  183.  
  184. '第二題,點選list,載入磚塊到command1 command2
  185. Private Sub List1_Click()
  186.     Text1 = List1.Text
  187.     bridx = List1.ListIndex
  188. End Sub
  189.  
  190. Private Sub Text1_Change()
  191.     For i = 0 To 15
  192.         If Mid(Text1, i + 1, 1) = "1" Then
  193.             Command1(i).BackColor = brkcolor(bridx)
  194.         Else
  195.             Command1(i).BackColor = &H8000000F
  196.         End If
  197.     Next
  198.     For i = 0 To 15
  199.         If Mid(Text1, i + 1, 1) = "1" Then
  200.             Command2(i).BackColor = brkcolor(bridx)
  201.         Else
  202.             Command2(i).BackColor = &H8000000F
  203.         End If
  204.     Next
  205. End Sub
  206.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement