【VB开源代码栏目提醒】:网学会员为广大网友收集整理了,用VB做游戏的源代码 - 编程语言,希望对大家有所帮助!
Label1 的 NameLabSnakeIndex0 Label2 的 NameLabTaiIndex0 Shape1 的 NameShaFootIndex0 Enum enMenuIndex m_Start m_Auto m_Fast m_Bar1 m_ShowNo m_ShowTo m_ShowNum m_ShowWen m_Bar2 m_ShowRect m_Line 此常数必须在最后 End Enum Enum enTo to_Up to_Down to_Left to_Right End Enum Dim ctTo As enTo ctZong As Long ctFoot As Long ctHead As Long Dim ctB As Long ctSize As Long ctH As Long ctL As Long ctEsc As Boolean Dim ctDown As Long ctRight As Long Dim ctFen As Long ctMaxFen As Long ctAutoFen As Long ctAutoMax As Long ctAuto As Boolean Private Sub Form_KeyDownKeyCode As Integer Shift As Integer Select Case KeyCode Case vbKeyUp: If ctTo to_Down Then ctTo to_Up Case vbKeyDown: If ctTo to_Up Then ctTo to_Down Case vbKeyLeft: If ctTo to_Right Then ctTo to_Left Case vbKeyRight: If ctTo to_Left Then ctTo to_Right End Select End Sub Private Sub ShowBackOptional AutoSize As Boolean Dim W As Single H As Single W1 As Single H1 As Single If Not AutoSize Then GoTo Back1 W1 Me.Width - Me.ScaleXMe.ScaleWidth Me.ScaleMode vbTwips 窗口边框宽度缇 H1 Me.Height - Me.ScaleYMe.ScaleHeight Me.ScaleMode vbTwips 窗口标题栏高度缇 W ctL ctSize ctB 2: H ctH ctSize ctB 2 W W Me.TextWidthA 14 留出 14 个字符的空白区显示成绩 For I 0 To Labtai.Count - 1 LabtaiI.Move ctRight ctB 0.5 ctB ctSize 1.2 I 1 Next W W1 Me.ScaleXW Me.ScaleMode vbTwips H H1 Me.ScaleYH Me.ScaleMode vbTwips Me.Move Screen.Width - W 0.5 Screen.Height - H 0.5 W H Back1: Me.Cls Me.Line ctB ctB-ctRight ctDown RGB0 155 0 BF If Not mmfastm_Line.Checked Then Exit Sub Dim nStr As String Me.Font.Size 9 W1 Me.TextWidthA: H1 ctSize - Me.TextHeightA 0.5 For H 0 To ctH 横线 Me.Line ctB ctB H ctSize-StepctRight - ctB 0 nStr H 1 Me.CurrentX ctB - Me.TextWidthnStr Me.CurrentY ctB H ctSize H1 If H ctH Then Me.Print nStr Next H1 Me.TextHeightA For H 0 To ctL 纵线 Me.Line ctB H ctSize ctB-Step0 ctDown - ctB nStr H 1 Me.CurrentX ctB H ctSize ctSize - Me.TextWidthnStr 0.5 Me.CurrentY ctB - H1 If H ctL Then Me.Print nStr Next End Sub Private Sub KjInit 初始化 Dim I As Long nEnd As Long S As Long H As Long ctFoot 2 同时出现的食物数 ctZong 10: ctTo to_Right 初始长度、方向 ctHead 0: ctFen 0 蛇头序号得分 ctSize 15 蛇身宽度控件大小像素 ctB 20 边框空白区像素 ctH 25: ctL 30 活动区行列数 ctDown ctB ctH ctSize 活动区底部位置 ctRight ctB ctL ctSize 活动区右部位置 Call ShowFen If mmfastm_ShowRect.Checked Then Labsnake0.BorderStyle 1 Else Labsnake0.BorderStyle 0 Labsnake0.Alignment 2: Labsnake0.BackColor 255 Randomize: H 1 IntctH - 1 Rnd 初始出发行 nEnd Labsnake.Count - 1 当前末尾序号 S ctZong If S nEnd Then S nEnd For I 0 To S If I ctZong Then Unload LabsnakeI Else If I nEnd Then Load LabsnakeI: LabsnakeI.Visible True LabsnakeI.Move ctB ctB ctSize H ctSize ctSize If mmfastm_ShowNum.Checked Then LabsnakeI.Caption I Else LabsnakeI.Caption End If Next Shafoot0.Shape 3: Shafoot0.FillStyle 0: Shafoot0.FillColor RGB0 0 255 Shafoot0.Move -ctB - ctSize 0 ctSize ctSize nEnd Shafoot.Count - 1 当前末尾序号 S ctFoot - 1 If S nEnd Then S nEnd For I 0 To S If I ctFoot - 1 Then Unload ShafootI Else If I nEnd Then Load ShafootI: ShafootI.Visible True Call RndFootI End If Next End Sub Private Sub Form_UnloadCancel As Integer ctEsc True If ctAutoMax ctAutoFen Then ctAutoMax ctAutoFen If ctMaxFen ctFen Then ctMaxFen ctFen SaveSetting Snake Opt AutoMax ctAutoMax SaveSetting Snake Opt MaxFen ctMaxFen End Sub Private Function KjIndexIndex As Long AddNum As Long KjIndex Index AddNum If AddNum 0 Then If KjIndex ctZong Then KjIndex KjIndex - ctZong - 1 Else If KjIndex 0 Then KjIndex KjIndex ctZong 1 End If End Function Private Sub LabTai_MouseDownIndex As Integer Button As Integer Shift As Integer X As Single Y As Singl