⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.frm

📁 贪吃蛇 做的不怎么精致 不过还能用
💻 FRM
📖 第 1 页 / 共 2 页
字号:
   Begin VB.Shape Shape1 
      FillColor       =   &H00FF0000&
      FillStyle       =   0  'Solid
      Height          =   375
      Index           =   0
      Left            =   4200
      Shape           =   3  'Circle
      Top             =   3480
      Width           =   375
   End
   Begin VB.Menu solo1 
      Caption         =   "游戏"
      Begin VB.Menu solo11 
         Caption         =   "开始游戏"
         Begin VB.Menu solo15 
            Caption         =   "游戏难度"
            Begin VB.Menu solo151 
               Caption         =   "低"
            End
            Begin VB.Menu solo152 
               Caption         =   "中"
            End
            Begin VB.Menu solo153 
               Caption         =   "高"
            End
         End
      End
      Begin VB.Menu solo12 
         Caption         =   "结束游戏"
      End
      Begin VB.Menu solo13 
         Caption         =   "暂停游戏"
      End
      Begin VB.Menu solo14 
         Caption         =   "继续游戏"
      End
   End
   Begin VB.Menu solo2 
      Caption         =   "其他"
      Begin VB.Menu solo21 
         Caption         =   "游戏说明"
      End
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim RunWay As Integer
Dim RunStep As Integer
Dim MaxLong As Integer
Private Type SnakeLocal
X As Long
Y As Long
End Type
Dim SnakeInitL(3) As SnakeLocal
Dim SnakeL As SnakeLocal
Dim C As Long
Dim n, m As Integer


Private Sub form_load()
n = 50
m = 50
Dim i As Integer
Timer1.Enabled = False
Timer2.Enabled = False
RunWay = 1
RunStep = 375
MaxLong = 3
For i = 0 To 3
SnakeInitL(i).X = Shape1(i).Left
SnakeInitL(i).Y = Shape1(i).Top
Next
InitGame
End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case 37
If RunWay <> 2 Then RunWay = 0
Case 38
If RunWay <> 3 Then RunWay = 1
Case 39
If RunWay <> 0 Then RunWay = 2
Case 40
If RunWay <> 1 Then RunWay = 3
End Select
End Sub

Private Sub Label9_Click()

End Sub

Private Sub solo12_Click()
If MsgBox("是否退出?", 4 + 32, "游戏提示!") = vbYes Then
End
End If
End Sub

Private Sub solo13_Click()
Timer1.Interval = 0
End Sub

Private Sub solo14_Click()
Timer1.Interval = 200
Frame1.Visible = False
End Sub

Private Sub solo151_Click()
InitGame
Timer1.Enabled = True

Timer2.Enabled = True
Frame1.Visible = False
Label1.Caption = 0
C = 0
Timer1.Interval = 300
Timer2.Interval = 10000
End Sub

Private Sub solo152_Click()
InitGame
Timer1.Enabled = True

Timer2.Enabled = True
Frame1.Visible = False
Label1.Caption = 0
C = 0
Timer1.Interval = 200
Timer2.Interval = 8000
End Sub

Private Sub solo153_Click()
InitGame
Timer1.Enabled = True

Timer2.Enabled = True
Frame1.Visible = False
Label1.Caption = 0
C = 0
Timer1.Interval = 100
Timer2.Interval = 5000
End Sub
Private Sub solo21_Click()
Frame1.Visible = True
Timer1.Interval = 0
End Sub

Private Sub solo22_Click()
Timer1.Interval = 200
Frame1.Visible = False
End Sub

Private Sub Timer1_Timer()
SnakeL.X = Shape1(0).Left
SnakeL.Y = Shape1(0).Top
Select Case RunWay
Case 0
Shape1(0).Left = Shape1(0).Left - RunStep
CheckWinne
CheckBean
CheckBean1
MoveSnake
Case 1
Shape1(0).Top = Shape1(0).Top - RunStep
CheckWinne
CheckBean
CheckBean1
MoveSnake
Case 2
Shape1(0).Left = Shape1(0).Left + RunStep
CheckWinne
CheckBean
CheckBean1
MoveSnake
Case 3
Shape1(0).Top = Shape1(0).Top + RunStep
CheckWinne
CheckBean
CheckBean1
MoveSnake
End Select
End Sub

Private Sub Timer2_Timer()
Dim X As Long, Y As Long
X = Rnd * (Line1.X2) + Line1.X1
Y = Rnd * (Line2.Y2) + Line2.Y1
Shape2.Top = Y
Shape2.Left = X
Shape2.Visible = True
End Sub
Private Sub CheckWinne()
Dim i As Integer
If Shape1(0).Left + Shape1(0).Width < Line1.X1 Or Shape1(0).Left > Line1.X2 Or Shape1(0).Top + Shape1(0).Width < Line2.Y1 Or Shape1(0).Top > Line2.Y2 Then
Timer1.Enabled = False
Timer2.Enabled = False
If MsgBox("你输了,是否继续?", 4 + 16, "游戏提示") = vbNo Then
End
End If
End If
For i = 1 To MaxLong
If Shape1(0).Left = Shape1(i).Left And Shape1(0).Top = Shape1(i).Top Then
Timer1.Enabled = False
Timer2.Enabled = False
If MsgBox("你输了,你咬到自己了!是否继续?", 4 + 16, "游戏提示") = vbNo Then End
Exit For
End If
Next
End Sub
Private Sub MoveSnake()
Dim tmpx As Long
Dim tmpy As Long
For i = 1 To MaxLong
tmpx = Shape1(i).Left
tmpy = Shape1(i).Top
Shape1(i).Left = SnakeL.X
Shape1(i).Top = SnakeL.Y
SnakeL.X = tmpx
SnakeL.Y = tmpy
Next
End Sub
Private Sub CheckBean()
If Shape2.Left > Shape1(0).Left And Shape2.Left < (Shape1(0).Left + Shape1(0).Width) And Shape2.Top > Shape1(0).Top And Shape2.Top < Shape1(0).Top + Shape1(0).Height Then
Shape2.Visible = False
MaxLong = MaxLong + 1
C = C + 10
Label1.Caption = C
Load Shape1(MaxLong)
Shape1(MaxLong).Top = Shape1(MaxLong - 1).Top + Shape1(MaxLong).Height
Shape1(MaxLong).Left = Shape1(MaxLong - 1).Left + Shape1(MaxLong).Width
Shape1(MaxLong).FillColor = &HFF0000
Shape1(MaxLong).Shape = 0
Shape1(MaxLong).Visible = True
End If
End Sub

Private Sub CheckBean1()
If Shape3.Left > Shape1(0).Left And Shape3.Left < (Shape1(0).Left + Shape1(0).Width) And Shape3.Top > Shape1(0).Top And Shape3.Top < Shape1(0).Top + Shape1(0).Height Then
Shape3.Visible = False
MaxLong = MaxLong + 1
C = C + 100
Label1.Caption = C
Load Shape1(MaxLong)
Shape1(MaxLong).Top = Shape1(MaxLong - 1).Top + Shape1(MaxLong).Height
Shape1(MaxLong).Left = Shape1(MaxLong - 1).Left + Shape1(MaxLong).Width
Shape1(MaxLong).FillColor = &HFF0000
Shape1(MaxLong).Shape = 0
Shape1(MaxLong).Visible = True
End If
End Sub
Private Sub InitGame()
Dim i As Integer
For i = 0 To MaxLong
If i >= 4 Then Unload Shape1(i)
If i <= 3 Then
Shape1(i).Left = SnakeInitL(i).X
Shape1(i).Top = SnakeInitL(i).Y
End If
Next
MaxLong = 3
RunWay = 0
End Sub

Private Sub Timer3_Timer()
Dim X As Long, Y As Long
X = Rnd * (Line1.X2) + Line1.X1
Y = Rnd * (Line2.Y2) + Line2.Y1
Shape3.Top = Y
Shape3.Left = X
Shape3.Visible = True
End Sub

Private Sub Timer4_Timer()
If Shape4(0).Left - 30 >= Frame1.Left Then
Shape4(0).Left = Shape4(0).Left - 30
Else
Shape4(0).Left = Frame1.Left + Frame1.Width
End If
If Shape4(1).Left - 30 >= Frame1.Left Then
Shape4(1).Left = Shape4(1).Left - 30
Else
Shape4(1).Left = Frame1.Left + Frame1.Width
End If
If Shape4(2).Left - 30 >= Frame1.Left Then
Shape4(2).Left = Shape4(2).Left - 30
Else
Shape4(2).Left = Frame1.Left + Frame1.Width
End If
If Shape4(3).Left - 30 >= Frame1.Left Then
Shape4(3).Left = Shape4(3).Left - 30
Else
Shape4(3).Left = Frame1.Left + Frame1.Width
End If
If Shape5.Left - 30 >= Frame1.Left Then
Shape5.Left = Shape5.Left - 30
Else
Shape5.Left = Frame1.Left + Frame1.Width
End If
If Shape6.Left - 30 >= Frame1.Left Then
Shape6.Left = Shape6.Left - 30
Else
Shape6.Left = Frame1.Left + Frame1.Width
End If
End Sub



Private Sub Timer5_Timer()

Label8.Left = Label8.Left + n
If Label8.Left + Label8.Width >= Frame2.Width Then n = -n
If Label8.Left < 0 Then n = -n
Label8.Top = Label8.Top + m
If Label8.Top + Label8.Height >= Frame2.Height Then m = -m
If Label8.Top < 0 Then m = -m
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -