当前位置:首页> 滚动 >

【环球新要闻】用vb编写贪吃蛇的教程_VB制作贪吃蛇游戏

时间:2023-03-10 09:40:01    来源:互联网


(资料图)

现在大家都会在网络上汲取相关知识内容,比如用vb编写贪吃蛇的教程_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 X As Long Y As Long End Type Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer) Dim C As Long If KeyCode = 27 Then End If KeyCode = 32 Then If Timer1.Enabled = True Then 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 If She(C).F = 2 Then Exit Sub She(C).F = 0 GFangXiang = True Case 38 If She(C).F = 3 Then Exit Sub She(C).F = 1 GFangXiang = True Case 39 If She(C).F = 0 Then Exit Sub She(C).F = 2 GFangXiang = True Case 40 If She(C).F = 1 Then Exit Sub 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 .ScaleMode = 3 HWB = .ScaleHeight / .ScaleWidth .ScaleWidth = 24 .ScaleHeight = 24 Label1.Move (Me.ScaleWidth - Label1.Width) / 2, (Me.ScaleHeight - Label1.Height) / 2 HuaTu 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: QingChu C = UBound(She) Select Case She(C).F Case 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 If Case 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 If Case 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 If Case 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 If End Select ZhuangTai(She(0).X, She(0).Y) = 0 For 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 Select Next TiaoZheng 1: GFangXiang = False ZhuangTai(She(C).X, She(C).Y) = 1 HuaTu Exit Sub 2: If MsgBox("游戏结束,点“是”重新开始游戏,点“否”", vbYesNo, "贪吃蛇") = vbYes Then ChuShiHua Else End End If End Sub Private Sub ChuShiHua() Me.Cls Timer1.Enabled = True Timer1.Interval = 200 Erase ZhuangTai ReDim She(2) She(0).F = 2 She(0).X = 9 She(0).Y = 11 ZhuangTai(9, 11) = 1 She(1).F = 2 She(1).X = 10 She(1).Y = 11 ZhuangTai(10, 11) = 1 She(2).F = 2 She(2).X = 11 She(2).Y = 11 ZhuangTai(11, 11) = 1 HuaTu ChanShengShiWu 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 As Long For I = 0 To 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() Randomize Timer 1: X = Int(Rnd * 24) Y = Int(Rnd * 24) If ZhuangTai(X, Y) > 0 Then GoTo 1: ZhuangTai(X, Y) = 2 Me.Line (X, Y)-(X + 1, Y + 1), RGB(255, 255, 0), BF End Sub 应该就是这个了。

上一篇:

下一篇:

【环球新要闻】用vb编写贪吃蛇的教程_VB制作贪吃蛇游戏

1、把代码复制到空窗体中按F5运行即可。2、OptionExplicitPrivateWithEventsTi

2023-03-10

简讯:96%受访者感同身受人挤路堵,但他们给出了留在广州的理由

96%受访者感同身受人挤路堵,但他们给出了留在广州的理由

2023-03-10

利物浦直播51live_利物浦直播360 天天微动态

1、欧洲足球(PPliveUUseePPstream)欧洲足球(SopcastSopcast)卫视体育台湾(S

2023-03-10

台球怎么玩规则图_台球怎么玩

1、台球有八球、九球、斯诺克等玩法。2、台球玩法规则:八球共15颗球,每人各7颗,黑色的八号球是公共的。3、双方轮流击球

2023-03-10

【当前热闻】2022年中国开源创新大赛初赛结果发布 76个项目晋级决赛

由中央网信办信息化发展局指导,中国互联网发展基金会、中国网络空间研究院、中国互联网投资基金联合主办,北京长风信息技术产业联盟承办的202

2023-03-09

扔掉你的小白鞋吧,过时了!今年推荐这双“春季鞋”,气质显高 天天实时

今年的春夏季节姐妹们千万不要再穿小白鞋,早就过时了,不仅很容易遇到撞衫的尴尬效果,而且整体搭配中也少了一些造型感。今年流行的是这双春

2023-03-09

DNF徽章有什么用_dnf治安官徽章有什么用

你是怎么拿到dnf警长徽章的?dnf警长徽章的作用是什么?f获得警长徽章的方法:参加来自西方的风活动。每次参加活动,总共

2023-03-09

世界热讯:东兴证券聘任副总经理刘亮为合规总监

券中社3月9日讯,东兴证券公告称,3月8日,刘亮担任公司合规总监事宜已获证券监管部门认可,即日起正式任职公司合规总监,任期至本届董事会届

2023-03-09

全球通讯!南昌红谷滩区“红石榴”孵化基地“开”出民族团结花

记者近日走进南昌市红谷滩区第三小学,周响云正在指导自己的帮扶小组成员练字。周响云告诉记者,为更好地凝心聚力、推动各民族青少年交流交融

2023-03-09

简讯:台州学院差吗_浙江台州学院怎么样

1、台州学院有两个分校一是椒江二是临海去汽车站看下有没到台州椒江或临海的如果没有的话,就去台州路桥的从路桥到椒江乘902就好了3~4块钱或打

2023-03-09