Excel version greedy snake SP1

zhaozj2021-02-16  33

The last time the published greedy snake program has bugs, in fact, the idea of ​​this process that has been completed last year, generates bugs when joining the user interactive interface. This time is slightly modified. Everyone covers the following statements to the same name function and process should be possible. Honestly, I am still not familiar with this VBA. When I changed the program, I had made Excel to generate an error. No matter how it is changed, I have created a program, and I will create a new file, copy the code in the past, actually normal! I still don't have much confidence in such something, everyone or more debug.

The first is the code in the macro.

Function main () gaming = False If Worksheets.Count <2 Then ActiveWorkbook.Sheets.Add after: = Worksheets (Worksheets.Count) Else Worksheets (Worksheets.Count) .Select End IfLoad UserForm1UserForm1.ShowEnd Function

Function game_over () if Timerset <> 0 dam Timerset = Killtimer (0, Timerset) Pulsed = false endiffness = false End if IF MSGBOX ("Game over ... Temporalily. Try Again?", VBOKCANCEL, "?????") = VBOK THEN RANGE (Cells (TOP 1, Left 1), Cells (Bottom - 1, Right - 1)). Interior.ColorIndex = 0 Range (Cells (TOP 1, Left 1), Cells (Bottom - 1 Right - 1)). ClearContents call game_initial else cells.clearcontents cells.interior.COLORINDEX = 0 gaming = false sendkeys "% {f4}" end ifnd function

The following is a window event processing code.

Private Sub UserForm_Initialize () UserForm1.Label1.Caption = "NO PLAY, NO GAME" Call game_initial If gaming Then UserForm1.Label2.Caption = "Arrow keys to move. P key to pause the game E key to end the game" Else UserForm1 .Label1.caption = "Something happened!" Call game_over end if End SUB

Private Sub UserForm_KeyDown (ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) If gaming Then If Not pulsed Then pulsed = True timerset = SetTimer (0, 0, 150, AddressOf snake_move) UserForm1.Label2.Caption = "Arrow keys to move . P key to pause the game E key to end the game "End If Select Case KeyCode Case vbKeyUp head_movement = 2 Case vbKeyDown head_movement = 4 Case vbKeyLeft head_movement = 3 Case vbKeyRight head_movement = 1 Case vbKeyP If timerset <> 0 Then timerset = KillTimer (0, TIMERSET) PULSED = FALSE End if Userform1.Label2.caption = "Game Paused. Any Key To Resume." Case VBKEYE CALL GAME_OVER End Select End IFEND Subprivate Sub Userform_Terminate ) MsgBox ("You Have Finished The Game with The Score of" Str (Score) Worksheets (1) .SelectensEnd Sub

Finally, the three Excel procedures have been sent in the screenshots running on my machine.

转载请注明原文地址:https://www.9cbs.com/read-22082.html

New Post(0)