excelでちょっとしたゲームを作る
2番目のシートで遊べる。
左右でよけるだけ。
Public Declare Function SetTimer Lib "USER32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long Public Declare Function KillTimer Lib "USER32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long Public Declare Function GetAsyncKeyState Lib "USER32" (ByVal vKey As Long) As Long Sub TimerStartStop() Set c = ThisWorkbook.Worksheets(1).Cells(1, 2) If c.Value = "" Then c.Value = SetTimer(0&, 31000&, 150&, AddressOf step) Else KillTimer 0&, c.Value c.Value = "" End If End Sub Sub step() On Error Resume Next n = ActiveSheet.Name Application.ScreenUpdating = False Set w1 = ThisWorkbook.Worksheets(1) Set w2 = ThisWorkbook.Worksheets(2) w2.Activate w2.Cells(30, 1).Select 'w2.Cells(1, w1.Cells(1, 3).Value).Value = "" If GetAsyncKeyState(37) <> 0 And w1.Cells(1, 3).Value > 1 Then w1.Cells(1, 3).Value = w1.Cells(1, 3).Value - 1 If GetAsyncKeyState(39) <> 0 And w1.Cells(1, 3).Value < 10 Then w1.Cells(1, 3).Value = w1.Cells(1, 3).Value + 1 For y = 2 To 20 For x = 1 To 10 w2.Cells(y - 1, x).Value = w2.Cells(y, x).Value Next x Next y If w2.Cells(1, w1.Cells(1, 3).Value) = "△" Then w2.Cells(1, w1.Cells(1, 3).Value) = "×" w2.Cells(2, 12).Value = w2.Cells(2, 12).Value - 200 Else w2.Cells(1, w1.Cells(1, 3).Value).Value = "●" w2.Cells(2, 12).Value = w2.Cells(2, 12).Value + 10 End If For i = 1 To 10 If Rnd < 0.1 Then w2.Cells(20, i) = "△" Else w2.Cells(20, i) = "" Next i ThisWorkbook.Worksheets(n).Activate Application.ScreenUpdating = True End Sub