教你用代码制作贪吃蛇小游戏 贪吃蛇小程序游戏编程
0
2024-09-16
您好,今天小编刀哥来为大家解答以上的问题简单的vbs贪吃蛇游戏代码,VB制作的贪吃蛇游戏很多小伙伴还不知道,现在就让我们一起来看看吧!
1、把复制到空模板中按F5运行即可。
2、 Option Explicit Private WithEvents Timer1 As Timer Private WithEvents Label1 As Label Dim GFangXiang As Boolean Dim HWB As Single Dim She() As ShenTi Dim X As Long, Y As Long Dim ZhuangTai(23, 23) As Long Private Type ShenTi F As Long Timer1.Enabled = False Label1.Visible = True Else Timer1.Enabled = True Label1.Visible = False End If End If C = UBound(She) If GFangXiang = True then Exit Sub Select Case KeyCode Case 37 如果 She(C).F = 2 则退出 Sub She(C).F = 0 GFangXiang = True Case 38 如果 She(C).F = 3 则退出 Sub She(C).F = 1 GFangXiang = True Case 39 如果 She(C).F = 0 则退出子程序 She(C).F = 2 GFangXiang = True Case 40 如果 She(C).F = 1 则退出子程序 She(C).F = 3 GFangXiang = True End Select End Sub Private Sub Form_Load() Me.AutoRedraw = True Me.BackColor = HC000 Me.FillColor = 255 Me.FillStyle = 0 Me.ScaleWidth = 24 Me.ScaleHeight = 24 Me.WindowState = 2 Set Timer1 = Controls.Add( "VB.Timer", "Timer1 ") Set Label1 = Controls.Add("VB.Label", "Label1") Label1.AutoSize = True Label1.BackStyle = 0 Label1 = "暂停" Label1.ForeColor = RGB(255, 255, 0) Label1.FontSize = 50 ChuShiHua End Sub Private Sub Form_Resize() On Error GoTo 1: With Me If .WindowState 1 then .Cls .Sca
leMode = 3 HWB = .ScaleHeight / .ScaleWidth .ScaleWidth = 24 .ScaleHeight = 24 Label1.Move (Me.ScaleWidth - Label1.Width) / 2, (Me.ScaleHeight - Label1.Height) / 2 画图 Me.Line (X , Y)-(X 1, Y 1), RGB(255, 255, 0), BF End If End With 1: End Sub Private Sub Timer1_Timer() Dim C As Long, I As Long On Error GoTo 2: 清楚 C = UBound(She) 选择 Case She(C).F Case 0 如果壮泰(She(C).X - 1, She(C).Y) = 2 则 C = C 1 ReDim 保留 She(C) She(C ).F = She(C - 1).F She(C).X = She(C - 1).X - 1 She(C).Y = She(C - 1).Y 单声实务 GoTo 1: ElseIf 状态(She(C).X - 1, She(C).Y) = 1 then GoTo 2: End If Case 1 If ZhuangTai(She(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 产生实务 GoTo 1: ElseIf 壮泰(She( C).X, She(C).Y - 1) = 1 then GoTo 2: End If Case 2 If ZhuangTai(She(C).X 1, She(C).Y) = 2 Then C = C 1 ReDim保留 She(C) She(C).F = She(C - 1).F She(C).X = She(C - 1).X 1 She(C).Y = She(C - 1)。 Y 生成实务 GoTo 1: ElseIf 壮泰(She(C).X 1, She(C).Y) = 1 then GoTo 2: End If Case 3 If 壮泰 (She(C).X, She(C).Y 1 ) = 2 则 C = C 1 ReDim 保留 She(C) She(C).F = She(C - 1).F She(C).X = She(C - 1).X She(C).Y = She(C - 1).Y 1 产生实务 GoTo 1: ElseIf 壮泰(She(C).GoTo 2
: End If End Select ZhuangTai(She(0).X, She(0.Y) = 0 For I = 0 To C 选择 Case She(I).F Case 0 She(I).X = She(I) . X - 1 案例 1 She(I).Y = She(I).Y - 1 案例 2 She(I).X = She(I).X 1 案例 3 She(I).Y = She(I) 。 Y 1 End Select 下一条正 1: GFangXiang = False ZhuangTai(She(C).点“否”", vbYesNo, "贪吃蛇") = vbYes then ChuShiHua Else End End If End Sub Private Sub ChuShiHua() Me.Cls Timer1.Enabled = True Timer1.Interval = 200 擦除庄台 ReDim She(2) She (0).F = 2 She(0).X = 9 She(0).Y = 11 庄台(9, 11) = 1 She (1).F = 2 She(1).X = 10 She(1 ).Y = 11 庄太(10, 11) = 1 She(2).F = 2 She(2).X = 11 She(2 ).Y = 11 状台(11, 11) = 1 花土禅师五 End Sub Private Sub QingChu() Dim I As Long For I = 0 To UBound(She) Me.Line (She(I).X, She(I) .Y)-(She(I).X 1, She(I).Y 1), Me.BackColor, BF Next End Sub Private Sub HuaTu() Dim I 只要 I = 0 到 UBound(She) ** *.Circle (She(I).X 0.5, She(I).Y 0.5), 0.49, RGB(255, 255, 0), , , HWB Next End Sub Private Sub TiaoZheng() Dim I As Long For I = 0 To UBound(She) - 1 She(I).F = She(I 1).F Next End Sub Private Sub ChanShengShiWu() 随机化定时器 1: ) = 2 Me.Line (X, Y)-(X 1, Y 1), RGB(255, 255, 0), BF End Sub 应该就是这个了。
本文就为大家分享到这里,希望小伙伴们会喜欢。