Module1.bas
资源名称:七八个vb游戏.rar [点击查看]
上传用户:tashmp
上传日期:2010-04-03
资源大小:882k
文件大小:5k
源码类别:
其他游戏
开发平台:
Visual Basic
- Attribute VB_Name = "Module1"
- Public Runway As Integer '标明蛇移动的方向 初始化为 0(左)
- Public p As Integer
- Public p1 As Integer
- Public Runstep As Integer '蛇头的宽度
- Public maxlong As Integer '蛇的长度 初始化为3
- Public Type str_snake_point '记录蛇的位置
- x As Integer
- y As Integer
- End Type
- Public snake_init(0 To 3) As str_snake_point '初始化记录蛇的位置
- Public snake_point As str_snake_point '记录蛇移动时的坐标
- '该动态数组保存蛇暂停时的位置
- 'Public snake_stopX() As Integer
- 'Public snake_stopY() As Integer
- 'Public snake_stop() As str_snake_point '该动态数组保存蛇暂停时的位置
- Public m_game As Integer '标明游戏关数
- Public score As Integer '分数的记录
- Public time1 As Integer
- Public Sub init_game() '初始化游戏
- 'Timer1.Enabled = True
- 'Timer2.Enabled = True
- 'ReDim snake_stopX(0 To maxlong)
- ' ReDim snake_stopY(0 To maxlong)
- ' MsgBox Str(LBound(snake_stopX))
- ' MsgBox Str(UBound(snake_stopX))
- Dim i As Integer
- 'ReDim sanke_stop(0 To maxlong)
- For i = 0 To maxlong Step 1
- If i >= 4 Then '把加载的控件卸载
- Unload Form1.Shape1(i)
- End If
- If i <= 3 Then
- Form1.Shape1(i).Left = snake_init(i).x
- Form1.Shape1(i).Top = snake_init(i).y
- 'snake_stop(i).x = Form1.Shape1(i).Left
- 'snake_stop(i).y = Form1.Shape1(i).Top
- End If
- Next i
- maxlong = 3
- p = 0
- p1 = 0
- Runway = 0
- 'm_game = 1 '初始化为第一关
- Screen.MousePointer = 99
- 'MsgBox App.Path + "ANIMAL"
- Screen.MouseIcon = LoadPicture(App.Path + "ANIMAL.ico")
- End Sub
- '蛇的移动
- Public Sub move_snake()
- Dim tempx As Integer
- Dim tempy As Integer '两个变量记录 要移动接点的坐标
- Dim i As Integer
- For i = 1 To maxlong Step 1
- tempx = Form1.Shape1(i).Left
- tempy = Form1.Shape1(i).Top
- Form1.Shape1(i).Left = snake_point.x
- Form1.Shape1(i).Top = snake_point.y
- snake_point.x = tempx
- snake_point.y = tempy
- 'snake_stopX(i) = tempx
- 'snake_stopY(i) = tempy
- Next i
- End Sub
- '判断游戏是否结束
- Public Sub vore_game()
- Dim i As Integer
- '游戏当蛇碰到边界 结束
- '蛇碰到自己 结束
- If Form1.Shape1(0).Left <= Form1.Line1.X1 + 50 Then
- '碰到左边界
- Form1.Timer1.Enabled = False
- Form1.Timer2.Enabled = False
- Form1.Timer3.Enabled = True
- End If
- If Form1.Shape1(0).Left + Form1.Shape1(i).Width > Form1.Line1.X2 Then
- '碰到右边界
- Form1.Timer1.Enabled = False
- Form1.Timer2.Enabled = False
- Form1.Timer3.Enabled = True
- End If
- If Form1.Shape1(0).Top < Form1.Line2.Y1 Then
- '碰到上边界
- Form1.Timer1.Enabled = False
- Form1.Timer2.Enabled = False
- Form1.Timer3.Enabled = True
- End If
- If Form1.Shape1(0).Top + Form1.Shape1(0).Height > Form1.Line2.Y2 Then
- '碰到下边界
- Form1.Timer1.Enabled = False
- Form1.Timer2.Enabled = False
- Form1.Timer3.Enabled = True
- End If
- For i = 1 To maxlong Step 1
- If Form1.Shape1(0).Left = Form1.Shape1(i).Left And _
- Form1.Shape1(0).Top = Form1.Shape1(i).Top Then
- Form1.Timer1.Enabled = False
- Form1.Timer2.Enabled = False
- Form1.Timer3.Enabled = True
- End If
- Next i
- ' If game = 1 Then
- 'If Form1.Shape1(0).Left < Form1.Line5.X1 And _
- ' Form1.Shape1(0).Left + Form1.Shape1(0).Width > Form1.Line5.X1 And _
- ' Form1.Shape1(0).Top > Form1.Line5.Y1 And _
- ' Form1.Shape1(0).Top < Form1.Line5.Y2 Then
- ' Form1.Timer1.Enabled = False
- ' Form1.Timer2.Enabled = False
- ' Form1.Timer3.Enabled = True
- ' End If
- 'End If
- End Sub
- Public Sub group_snake()
- 'Set frm = Form1
- If Form1.Shape2.Left > Form1.Shape1(i).Left And _
- Form1.Shape2.Left < Form1.Shape1(i).Left + Form1.Shape1(0).Width And _
- Form1.Shape2.Top > Form1.Shape1(i).Top And _
- Form1.Shape2.Top < Form1.Shape1(i).Top + Form1.Shape1(i).Height Then
- '向左吃食物(满足上面条件 既吃到食物)
- Form1.Shape2.Visible = False '
- maxlong = maxlong + 1 '蛇身加1
- Load Form1.Shape1(maxlong) '加载一个数组控件
- '初始化位置
- Form1.Shape1(maxlong).Left = Form1.Shape1(maxlong - 1).Left + Form1.Shape1(maxlong - 1).Width
- Form1.Shape1(maxlong).Top = Form1.Shape1(maxlong - 1).Top + Form1.Shape1(maxlong - 1).Height
- Randomize
- Form1.Shape1(maxlong).FillColor = RGB(Rnd * 255, Rnd * 255, Rnd * 255)
- Form1.Shape1(maxlong).Shape = 0
- Form1.Shape1(maxlong).Visible = True
- score = score + 10
- Form1.Labelscore.Caption = score
- End If
- If score = 200 Then
- m_game = m_game + 1
- Form1.Timer1.Enabled = False
- Form1.Timer2.Enabled = False
- MsgBox "恭喜你闯过第" & m_game - 1 & "关" & "按回车键 开始下一关!!", 64
- score = 0
- Call init_game
- time1 = Form1.Timer1.Interval - m_game * 15
- Form1.Timer2.Interval = Form1.Timer2.Interval - m_game * 400
- If time1 <= 0 Then
- MsgBox "高手 你闯过了所有的关数 "
- time1 = 200
- Form1.Timer1.Enabled = False
- Form1.Timer2.Enabled = False
- End If
- Form1.Timer1.Interval = time1
- Form1.Labelscore.Caption = score
- Form1.Timer1.Enabled = True
- Form1.Timer2.Enabled = True
- End If
- End Sub
- '停止游戏
- Public Sub stop_game()
- Form1.Timer1.Enabled = False
- Form1.Timer2.Enabled = False
- End Sub
- '解除暂停
- Public Sub start_game()
- Form1.Timer1.Enabled = True
- Form1.Timer2.Enabled = True
- End Sub