Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal ms As LongPtr)
Private Declare Sub Sleep Lib "kernel32" (ByVal ms As Long)
Public flag As Boolean
Sub game()
Dim i As Integer
Dim j As Integer
Dim c As Integer
Dim retu As Integer
Randomize
c = 0
Range("c10").Select
Do While flag
If c Mod 2 = 0 Then
retu = Int(5 * Rnd + 1)
Cells(2, retu) = "●"
End If
Sleep 100
DoEvents
For i = 10 To 2 Step -1
For j = 1 To 5
Cells(i, j) = Cells(i - 1, j)
Next j
Next i
If Selection = "●" Then
MsgBox "Game Over"
flag = False
End If
c = c + 1
Loop
Range("A2:E10") = ""
End Sub
Sub game_1()
Dim i As Integer
Dim c As Integer
c = 0
Do While flag
If c Mod 9 = 0 Then
Cells(2, 1) = "●"
End If
Sleep 100
DoEvents
For i = 10 To 2 Step -1
Cells(i, 1) = Cells(i - 1, 1)
Next i
c = c + 1
Loop
Range("A2:A10") = ""
End Sub
Sub game_2()
Dim i As Integer
Dim c As Integer
Dim retu As Integer
Randomize
c = 0
Do While flag
If c Mod 4 = 0 Then
retu = Int(5 * Rnd + 1)
Cells(2, retu) = "●"
End If
Sleep 100
DoEvents
For i = 10 To 2 Step -1
Cells(i, 1) = Cells(i - 1, 1)
Next i
c = c + 1
Loop
Range("A2:A10") = ""
End Sub
Sub game_3()
Dim i As Integer
Dim j As Integer
Dim c As Integer
Dim retu As Integer
Randomize
c = 0
Do While flag
If c Mod 4 = 0 Then
retu = Int(5 * Rnd + 1)
Cells(2, retu) = "●"
End If
Sleep 100
DoEvents
For i = 10 To 2 Step -1
For j = 1 To 5
Cells(i, j) = Cells(i - 1, j)
Next j
Next i
c = c + 1
Loop
Range("A2:E10") = ""
End Sub
Sub game_4()
Dim i As Integer
Dim j As Integer
Dim c As Integer
Dim retu As Integer
Randomize
c = 0
Range("c10").Select
Do While flag
If c Mod 4 = 0 Then
retu = Int(5 * Rnd + 1)
Cells(2, retu) = "●"
End If
Sleep 100
DoEvents
For i = 10 To 2 Step -1
For j = 1 To 5
Cells(i, j) = Cells(i - 1, j)
Next j
Next i
If Selection = "●" Then
MsgBox "GameOver"
flag = False
End If
c = c + 1
Loop
Range("A2:E10") = ""
End Sub
Private Sub CommandButton1_Click()
If flag Then
flag = False
CommandButton1.Caption = "スタート"
Else
flag = True
CommandButton1.Caption = "ストップ"
Call game_4
End If
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Column = 6 Then
Cells(Target.Row, 5).Select
End If
End Sub