导读 您好,今天小编胡舒来为大家解答以上的问题。编程小游戏代码弹球,编程小游戏代码相信很多小伙伴还不知道,现在让我们一起来看看吧!1、贪吃...

您好,今天小编胡舒来为大家解答以上的问题。编程小游戏代码弹球,编程小游戏代码相信很多小伙伴还不知道,现在让我们一起来看看吧!

1、贪吃蛇Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)Dim C As LongIf KeyCode = 27 Then EndIf KeyCode = 32 Then If ***.enabled = True Then ***.enabled = False ***.visible = True Else ***.enabled = True ***.visible = False End IfEnd IfC = UBound(She)If GFangXiang = True Then Exit SubSelect Case KeyCodeCase 37 If She(C).F = 2 Then Exit Sub She(C).F = 0 GFangXiang = TrueCase 38 If She(C).F = 3 Then Exit Sub She(C).F = 1 GFangXiang = TrueCase 39 If She(C).F = 0 Then Exit Sub She(C).F = 2 GFangXiang = TrueCase 40 If She(C).F = 1 Then Exit Sub She(C).F = 3 GFangXiang = TrueEnd SelectEnd SubPrivate Sub Form_Load()***.autoredraw = True***.backcolor = &HC000&***.fillcolor = 255***.fillstyle = 0***.scalewidth = 24***.scaleheight = 24***.windowstate = 2Set Timer1 = ***.add("***.timer", "Timer1")Set Label1 = ***.add("***.label", "Label1")***.autosize = True***.backstyle = 0Label1 = "暂停"***.forecolor = RGB(255, 255, 0)***.fontsize = 50ChuShiHuaEnd SubPrivate Sub Form_Resize()On Error GoTo 1:With Me If .WindowState <> 1 Then .Cls .ScaleMode = 3 HWB = .ScaleHeight / .ScaleWidth .ScaleWidth = 24 .ScaleHeight = 24 ***.move (***.scalewidth - ***.width) / 2, (***.scaleheight - ***.height) / 2 HuaTu ***.line (X, Y)-(X + 1, Y + 1), RGB(255, 255, 0), BF End IfEnd With1:End SubPrivate Sub Timer1_Timer()Dim C As Long, I As LongOn Error GoTo 2:QingChuC = UBound(She)Select Case She(C).FCase 0 If ZhuangTai(She(C).X - 1, She(C).Y) = 2 Then C = C + 1 ReDim Preserve She(C) She(C).F = She(C - 1).F She(C).X = She(C - 1).X - 1 She(C).Y = She(C - 1).Y ChanShengShiWu GoTo 1: ElseIf ZhuangTai(She(C).X - 1, She(C).Y) = 1 Then GoTo 2: End IfCase 1 If ZhuangTai(She(C).X, She(C).Y - 1) = 2 Then C = C + 1 ReDim Preserve She(C) She(C).F = She(C - 1).F She(C).X = She(C - 1).X She(C).Y = She(C - 1).Y - 1 ChanShengShiWu GoTo 1: ElseIf ZhuangTai(She(C).X, She(C).Y - 1) = 1 Then GoTo 2: End IfCase 2 If ZhuangTai(She(C).X + 1, She(C).Y) = 2 Then C = C + 1 ReDim Preserve She(C) She(C).F = She(C - 1).F She(C).X = She(C - 1).X + 1 She(C).Y = She(C - 1).Y ChanShengShiWu GoTo 1: ElseIf ZhuangTai(She(C).X + 1, She(C).Y) = 1 Then GoTo 2: End IfCase 3 If ZhuangTai(She(C).X, She(C).Y + 1) = 2 Then C = C + 1 ReDim Preserve She(C) She(C).F = She(C - 1).F She(C).X = She(C - 1).X She(C).Y = She(C - 1).Y + 1 ChanShengShiWu GoTo 1: ElseIf ZhuangTai(She(C).X, She(C).Y + 1) = 1 Then GoTo 2: End IfEnd SelectZhuangTai(She(0).X, She(0).Y) = 0For I = 0 To C Select Case She(I).F Case 0 She(I).X = She(I).X - 1 Case 1 She(I).Y = She(I).Y - 1 Case 2 She(I).X = She(I).X + 1 Case 3 She(I).Y = She(I).Y + 1 End SelectNextTiaoZheng1:GFangXiang = FalseZhuangTai(She(C).X, She(C).Y) = 1HuaTuExit Sub2:If MsgBox("游戏结束。

2、点“是”重新开始游戏。

3、点“否”", vbYesNo, "贪吃蛇") = vbYes Then ChuShiHuaElse EndEnd IfEnd SubPrivate Sub ChuShiHua()***.cls***.enabled = True***.interval = 200Erase ZhuangTaiReDim She(2)She(0).F = 2She(0).X = 9She(0).Y = 11ZhuangTai(9, 11) = 1She(1).F = 2She(1).X = 10She(1).Y = 11ZhuangTai(10, 11) = 1She(2).F = 2She(2).X = 11She(2).Y = 11ZhuangTai(11, 11) = 1HuaTuChanShengShiWuEnd SubPrivate Sub QingChu()Dim I As LongFor I = 0 To UBound(She) ***.line (She(I).X, She(I).Y)-(She(I).X + 1, She(I).Y + 1), ***.backcolor, BFNextEnd SubPrivate Sub HuaTu()Dim I As LongFor I = 0 To UBound(She) ***.circle (She(I).X + 0.5, She(I).Y + 0.5), 0.49, RGB(255, 255, 0), , , HWBNextEnd SubPrivate Sub TiaoZheng()Dim I As LongFor I = 0 To UBound(She) - 1 She(I).F = She(I + 1).FNextEnd SubPrivate Sub ChanShengShiWu()Randomize Timer1:X = Int(Rnd * 24)Y = Int(Rnd * 24)If ZhuangTai(X, Y) > 0 Then GoTo 1:ZhuangTai(X, Y) = 2***.line (X, Y)-(X + 1, Y + 1), RGB(255, 255, 0), BFEnd Sub直接复制到空代码窗口。

本文就为大家分享到这里,希望小伙伴们会喜欢。