在窗体上添加6个时钟控件,两个个shape控件,一个shape1的index属性为0,两个标签,以下代码:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 37 And Timer3.Enabled = False Then
Timer1.Enabled = True
Timer2.Enabled = False
Timer3.Enabled = False
Timer4.Enabled = False
End If
If KeyCode = 38 And Timer4.Enabled = False Then
Timer2.Enabled = True
Timer1.Enabled = False
Timer3.Enabled = False
Timer4.Enabled = False
End If
If KeyCode = 39 And Timer1.Enabled = False Then
Timer3.Enabled = True
Timer1.Enabled = False
Timer2.Enabled = False
Timer4.Enabled = False
End If
If KeyCode = 40 And Timer2.Enabled = False Then
Timer4.Enabled = True
Timer2.Enabled = False
Timer3.Enabled = False
Timer1.Enabled = False
End If
End Sub
Private Sub Form_Load()
Randomize
x = Fix(10 * Rnd + 1)
y = Fix(10 * Rnd + 1)
Shape2.Left = x * 300
Shape2.Top = y * 300
For i = 1 To 300
Load Shape1(i)
Next i
End Sub
Private Sub Timer1_Timer()
Shape1(0).Left = Shape1(0).Left - 300
If Shape1(0).Left < -50 Then
Timer1.Enabled = False
MsgBox "游戏结束,你的得分是:" + Label1.Caption
End If
End Sub
Private Sub Timer2_Timer()
Shape1(0).Top = Shape1(0).Top - 300
If Shape1(0).Top < -50 Then
Timer2.Enabled = False
MsgBox "游戏结束,你的得分是:" + Label1.Caption
End If
End Sub
Private Sub Timer3_Timer()
Shape1(0).Left = Shape1(0).Left + 300
If Shape1(0).Left > 6050 Then
Timer3.Enabled = False
MsgBox "游戏结束,你的得分是:" + Label1.Caption
End If
End Sub
Private Sub Timer4_Timer()
Shape1(0).Top = Shape1(0).Top + 300
If Shape1(0).Top > 6050 Then
Timer4.Enabled = False
MsgBox "游戏结束,你的得分是:" + Label1.Caption
End If
End Sub
Private Sub Timer5_Timer()
If Shape1(0).Left <= Shape2.Left + 50 And Shape1(0).Left >= Shape2.Left - 50 And Shape1(0).Top <= Shape2.Top + 50 And Shape1(0).Top >= Shape2.Top - 50 Then
If Shape2.Visible = True Then
Label1.Caption = Label1.Caption + 5
Shape2.Visible = False
Randomize
x = Fix(10 * Rnd + 1)
y = Fix(10 * Rnd + 1)
Shape2.Left = x * 300
Shape2.Top = y * 300
Shape2.Visible = True
End If
End If
End Sub
Private Sub Timer6_Timer()
If Timer1.Enabled = True Or Timer2.Enabled = True Or Timer3.Enabled = True Or Timer4.Enabled = True Then
Label2.Caption = Label2.Caption - 1
End If
If Label2.Caption = 0 Then
Timer1.Enabled = False
Timer2.Enabled = False
Timer3.Enabled = False
Timer4.Enabled = False
Timer6.Enabled = False
Form1.KeyPreview = False
MsgBox "游戏结束,你的得分是:" + Label1.Caption
End If
End Sub
就是无法增加贪吃蛇的长度,会的朋友请留言指教!我想用控件数组增加长度
VB贪吃蛇游戏问题
答案:1 悬赏:50 手机版
解决时间 2021-04-29 03:00
- 提问者网友:人傍凄凉立暮秋
- 2021-04-28 17:35
最佳答案
- 五星知识达人网友:蓝房子
- 2021-04-28 19:01
麻烦死。邮箱给我。我发源程序给你
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯