用VB编写一个小游戏

用VB编写一个小游戏,第1张

'定义蛇的运动速度枚举值

Private Enum tpsSpeed

QUICKLY = 0

SLOWLY = 1

End Enum

'定义蛇的运动方向枚举值

Private Enum tpsDirection

D_UP = 38

D_DOWN = 40

D_LEFT = 37

D_RIGHT = 39

End Enum

'定义运动区域4个禁区的枚举值

Private Enum tpsForbiddenZone

FZ_TOP = 30

FZ_BOTTOM = 5330

FZ_LEFT = 30

FZ_RIGHT = 5730

End Enum

'定义蛇头及身体初始化数枚举值

Private Enum tpsSnake

SNAKEONE = 1

SNAKETWO = 2

SNAKETHREE = 3

SNAKEFOUR = 4

End Enum

'定义蛇宽度的常量

Private Const SNAKEWIDTH As Integer = 100

'该过程用于显示游戏信息

Private Sub Form_Load()

MeShow

MelblTitle = "BS贪食蛇 — (版本 " & AppMajor & "" & AppMinor & "" & AppRevision & ")"

MeCaption = MelblTitleCaption

frmSplashShow 1

End Sub

'该过程用于使窗体恢复原始大小

Private Sub Form_Resize()

If MeWindowState > 1 Then

MeCaption = ""

MeHeight = 6405 '窗体高度为 6405 缇

MeWidth = 8535 '窗体宽度为 8535 缇

MeLeft = (ScreenWidth - Width) \ 2

MeTop = (ScreenHeight - Height) \ 2

End If

End Sub

'该过程用于重新开始开始游戏

Private Sub cmdGameStart_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

Beep

msg = MsgBox("您确认要重新开始游戏吗?", 4 + 32, "BS贪食蛇")

If msg = 6 Then Call m_subGameInitialize

End Sub

'该过程用于暂停/运行游戏

Private Sub chkPause_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

If MechkPauseCaption = "暂停游戏(&P)" Then

MetmrSnakeMoveEnabled = False

MetmrGameTimeEnabled = False

MepicMoveAreaEnabled = False

MelblPauseLabVisible = True

MechkPauseCaption = "继续游戏(&R)"

Else

MetmrSnakeMoveEnabled = True

MetmrGameTimeEnabled = True

MepicMoveAreaEnabled = True

MelblPauseLabVisible = False

MechkPauseCaption = "暂停游戏(&P)"

End If

End Sub

'该过程用于显示游戏规则

Private Sub cmdGameRules_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

Beep

MsgBox " BS贪食蛇:一个规则最简单的趣味游戏,您将用键盘" & Chr(13) & _

"上的4个方向键来控制蛇的运动方向。在运动过程中蛇" & Chr(13) & _

"不能后退,蛇的头部也不能接触到运动区域的边线以外" & Chr(13) & _

"和蛇自己的身体,否则就游戏失败。在吃掉随机出现的" & Chr(13) & _

"果子后,蛇的身体会变长,越长难度越大。祝您好运!!", 0 + 64, "游戏规则"

End Sub

'该过程用于显示游戏开发信息

Private Sub cmdAbout_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

Beep

MsgBox "BS贪食蛇" & "(V-" & AppMajor & "" & AppMinor & "版本)" & Chr(13) & Chr(13) & _

"" & Chr(13) & Chr(13) & _

"由PigheadPrince设计制作" & Chr(13) & _

"CopyRight(C)2002,BestSoftTCG", 0, "关于本游戏"

End Sub

'该过程用于退出游戏

Private Sub cmdExit_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

Beep

msg = MsgBox("您要退出本游戏吗?", 4 + 32, "BS贪食蛇")

Select Case msg

Case 6

End

Case 7

MechkWindowButton(2)Value = 0

Exit Sub

End Select

End Sub

'该过程用于拖动窗体_(点击图标)

Private Sub imgWindowTop_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

ReleaseCapture

SendMessage Mehwnd, WM_SYSCOMMAND, SC_MOVE, 0

End Sub

'该共用过程用于处理窗体控制按钮组的相关操作_(锁定、最小化、退出)

Private Sub chkWindowButton_MouseUp(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)

If Button > 1 Then Exit Sub

Select Case Index

Case 0 '锁定窗体

If MechkWindowButton(0)Value = 1 Then

MeimgWindowTopBorderStyle = 0

MeimgWindowTopEnabled = False

Else

MeimgWindowTopBorderStyle = 1

MeimgWindowTopEnabled = True

End If

Case 1 '最小化

MeWindowState = 1

MechkWindowButton(1)Value = 0

MeCaption = "BS贪食蛇 — (V-" & AppMajor & "" & AppMinor & "版本)"

Case 2 '退出

Beep

msg = MsgBox("您要退出本游戏吗?", 4 + 32, "BS贪食蛇")

Select Case msg

Case 6

End

Case 7

MechkWindowButton(2)Value = 0

Exit Sub

End Select

End Select

End Sub

'该过程用于设置蛇运动速度的快慢

Private Sub hsbGameSpeed_Change()

MetmrSnakeMoveInterval = MehsbGameSpeedValue

End Sub

'该过程用于通过键盘的方向键改变蛇的运动方向

Private Sub picMoveArea_KeyDown(KeyCode As Integer, Shift As Integer)

Select Case g_intDirection

Case D_UP

If KeyCode = D_DOWN Then Exit Sub

Case D_DOWN

If KeyCode = D_UP Then Exit Sub

Case D_LEFT

If KeyCode = D_RIGHT Then Exit Sub

Case D_RIGHT

If KeyCode = D_LEFT Then Exit Sub

End Select

g_intDirection = KeyCode

End Sub

'该计时循环过程用于计算游戏耗费的秒数并显示

Private Sub tmrGameTime_Timer()

g_lngGameTime = g_lngGameTime + 1

MelblGameTimeCaption = g_lngGameTime & "秒"

End Sub

'该计时循环过程用于控制蛇的行动轨迹

Private Sub tmrSnakeMove_Timer()

Dim lngSnakeX As Long, lngSnakeY As Long, lngSnakeColor As Long

Dim lngPointX As Long, lngPointY As Long, lngPointColor As Long

Randomize

MepicMoveAreaSetFocus

MepicMoveAreaCls

'确认蛇头的运动方向并获取新的位置

Select Case g_intDirection

Case D_UP '向上运动

g_udtSnake(SNAKEONE)Snake_CurX = g_udtSnake(SNAKEONE)Snake_OldX

g_udtSnake(SNAKEONE)Snake_CurY = g_udtSnake(SNAKEONE)Snake_OldY

g_udtSnake(SNAKEONE)Snake_CurY = g_udtSnake(SNAKEONE)Snake_CurY - SNAKEWIDTH

Case D_DOWN '向下运动

g_udtSnake(SNAKEONE)Snake_CurX = g_udtSnake(SNAKEONE)Snake_OldX

g_udtSnake(SNAKEONE)Snake_CurY = g_udtSnake(SNAKEONE)Snake_OldY

g_udtSnake(SNAKEONE)Snake_CurY = g_udtSnake(SNAKEONE)Snake_CurY + SNAKEWIDTH

Case D_LEFT '向左运动

g_udtSnake(SNAKEONE)Snake_CurX = g_udtSnake(SNAKEONE)Snake_OldX

g_udtSnake(SNAKEONE)Snake_CurX = g_udtSnake(SNAKEONE)Snake_CurX - SNAKEWIDTH

g_udtSnake(SNAKEONE)Snake_CurY = g_udtSnake(SNAKEONE)Snake_OldY

Case D_RIGHT '向右运动

g_udtSnake(SNAKEONE)Snake_CurX = g_udtSnake(SNAKEONE)Snake_OldX

g_udtSnake(SNAKEONE)Snake_CurX = g_udtSnake(SNAKEONE)Snake_CurX + SNAKEWIDTH

g_udtSnake(SNAKEONE)Snake_CurY = g_udtSnake(SNAKEONE)Snake_OldY

End Select

'根据新的位置绘制蛇头

lngSnakeX = g_udtSnake(SNAKEONE)Snake_CurX

lngSnakeY = g_udtSnake(SNAKEONE)Snake_CurY

lngSnakeColor = g_udtSnake(SNAKEONE)Snake_Color

MepicMoveAreaPSet (lngSnakeX, lngSnakeY), lngSnakeColor

'移动蛇身体其他部分的位置

For i = 2 To g_intSnakeLength

g_udtSnake(i)Snake_CurX = g_udtSnake(i - 1)Snake_OldX

g_udtSnake(i)Snake_CurY = g_udtSnake(i - 1)Snake_OldY

lngSnakeX = g_udtSnake(i)Snake_CurX

lngSnakeY = g_udtSnake(i)Snake_CurY

lngSnakeColor = g_udtSnake(i)Snake_Color

MepicMoveAreaPSet (lngSnakeX, lngSnakeY), lngSnakeColor

Next i

'更新蛇旧的坐标位置

For j = 1 To g_intSnakeLength

g_udtSnake(j)Snake_OldX = g_udtSnake(j)Snake_CurX

g_udtSnake(j)Snake_OldY = g_udtSnake(j)Snake_CurY

Next j

'判断蛇在移动中是否到了禁区而导致游戏失败

If m_funMoveForbiddenZone(g_udtSnake(SNAKEONE)Snake_CurX, g_udtSnake(SNAKEONE)Snake_CurY) Then

Beep

MsgBox "您的蛇移动到了禁区,游戏失败!", 0 + 16, "BS贪食蛇"

MetmrSnakeMoveEnabled = False

MetmrGameTimeEnabled = False

MepicMoveAreaVisible = False

Exit Sub

End If

'判断蛇在移动中是否碰到了自己的身体而导致游戏失败

If m_funTouchSnakeBody(g_udtSnake(SNAKEONE)Snake_CurX, g_udtSnake(SNAKEONE)Snake_CurY) Then

Beep

MsgBox "您的蛇在移动中碰到了自己的身体,游戏失败!", 0 + 16, "BS贪食蛇"

MetmrSnakeMoveEnabled = False

MetmrGameTimeEnabled = False

MepicMoveAreaVisible = False

Exit Sub

End If

'判断蛇是否吃到了果子

If m_funEatPoint(g_udtSnake(SNAKEONE)Snake_CurX, g_udtSnake(SNAKEONE)Snake_CurY) Then

'累加玩家的得分并刷新得分显示

g_intPlayerScore = g_intPlayerScore + 1

MelblYourScoreCaption = g_intPlayerScore & "分"

Call m_subAddSnake '加长蛇的身体

Call m_subGetPoint '获取下一个果子的位置和颜色

Else

'绘制果子

lngPointX = g_udtPointPoint_X

lngPointY = g_udtPointPoint_Y

lngPointColor = g_udtPointPoint_Color

MepicMoveAreaPSet (lngPointX, lngPointY), lngPointColor

End If

End Sub

'该私有子过程用于初始化游戏

Private Sub m_subGameInitialize()

Erase g_udtSnake '清空蛇的结构数组

g_intPlayerScore = 0 '清空玩家的得分

g_lngGameTime = 0 '清空游戏耗费的秒数

g_intDirection = D_DOWN '设定蛇的初始运动方向为下

g_intSnakeLength = 4 '设定蛇的初始长度

ReDim g_udtSnake(1 To g_intSnakeLength) '重新定义蛇的长度

'定义蛇头部的数据

With g_udtSnake(SNAKEONE)

Snake_OldX = 530

Snake_OldY = 530

Snake_Color = vbBlack

End With

'定义蛇身第2节的数据

With g_udtSnake(SNAKETWO)

Snake_OldX = 530

Snake_OldY = 430

Snake_Color = vbGreen

End With

'定义蛇身第3节的数据

With g_udtSnake(SNAKETHREE)

Snake_OldX = 530

Snake_OldY = 330

Snake_Color = vbYellow

End With

'定义蛇身第4节的数据

With g_udtSnake(SNAKEFOUR)

Snake_OldX = 530

Snake_OldY = 230

Snake_Color = vbRed

End With

MepicMoveAreaVisible = True

MelblYourScoreCaption = g_intPlayerScore & "分"

MelblGameTimeCaption = g_lngGameTime & "秒"

MetmrSnakeMoveInterval = MehsbGameSpeedValue

MetmrSnakeMoveEnabled = True

MetmrGameTimeEnabled = True

Call m_subGetPoint '获取第一个果子的位置和颜色

End Sub

'该私有子过程用于返回获取的果子的位置和颜色信息

Private Sub m_subGetPoint()

Dim lngRedValue As Long, lngGreenValue As Long, lngBlueValue As Long

Dim lngPointX As Long, lngPointY As Long, lngPointColor As Long

'随机获取果子的颜色

lngRedValue = Int((255 - 0 + 1) Rnd + 0)

lngGreenValue = Int((255 - 0 + 1) Rnd + 0)

lngBlueValue = Int((255 - 0 + 1) Rnd + 0)

lngPointColor = RGB(lngRedValue, lngGreenValue, lngBlueValue)

'随机获取果子的位置

lngPointX = Int((FZ_LEFT - FZ_RIGHT + 1) Rnd + FZ_RIGHT)

lngPointY = Int((FZ_TOP - FZ_BOTTOM + 1) Rnd + FZ_BOTTOM)

MePSet (lngPointX, lngPointY), lngPointColor

'设置函数返回值

With g_udtPoint

Point_X = lngPointX

Point_Y = lngPointY

Point_Color = lngPointColor

End With

End Sub

'定义蛇的运动速度枚举值

Private Enum tpsSpeed

QUICKLY = 0

SLOWLY = 1

End Enum

'定义蛇的运动方向枚举值

Private Enum tpsDirection

D_UP = 38

D_DOWN = 40

D_LEFT = 37

D_RIGHT = 39

End Enum

'定义运动区域4个禁区的枚举值

Private Enum tpsForbiddenZone

FZ_TOP = 30

FZ_BOTTOM = 5330

FZ_LEFT = 30

FZ_RIGHT = 5730

End Enum

'定义蛇头及身体初始化数枚举值

Private Enum tpsSnake

SNAKEONE = 1

SNAKETWO = 2

SNAKETHREE = 3

SNAKEFOUR = 4

End Enum

'定义蛇宽度的常量

Private Const SNAKEWIDTH As Integer = 100

'该过程用于显示游戏信息

Private Sub Form_Load()

MeShow

MelblTitle = "BS贪食蛇 — (版本 " & AppMajor & "" & AppMinor & "" & AppRevision & ")"

MeCaption = MelblTitleCaption

frmSplashShow 1

End Sub

'该过程用于使窗体恢复原始大小

Private Sub Form_Resize()

If MeWindowState <> 1 Then

MeCaption = ""

MeHeight = 6405 '窗体高度为 6405 缇

MeWidth = 8535 '窗体宽度为 8535 缇

MeLeft = (ScreenWidth - Width) \ 2

MeTop = (ScreenHeight - Height) \ 2

End If

End Sub

'该过程用于重新开始开始游戏

Private Sub cmdGameStart_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

Beep

msg = MsgBox("您确认要重新开始游戏吗?", 4 + 32, "BS贪食蛇")

If msg = 6 Then Call m_subGameInitialize

End Sub

'该过程用于暂停/运行游戏

Private Sub chkPause_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

If MechkPauseCaption = "暂停游戏(&P)" Then

MetmrSnakeMoveEnabled = False

MetmrGameTimeEnabled = False

MepicMoveAreaEnabled = False

MelblPauseLabVisible = True

MechkPauseCaption = "继续游戏(&R)"

Else

MetmrSnakeMoveEnabled = True

MetmrGameTimeEnabled = True

MepicMoveAreaEnabled = True

MelblPauseLabVisible = False

MechkPauseCaption = "暂停游戏(&P)"

End If

End Sub

'该过程用于显示游戏规则

Private Sub cmdGameRules_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

Beep

MsgBox " BS贪食蛇:一个规则最简单的趣味游戏,您将用键盘" & Chr(13) & _

"上的4个方向键来控制蛇的运动方向。在运动过程中蛇" & Chr(13) & _

"不能后退,蛇的头部也不能接触到运动区域的边线以外" & Chr(13) & _

"和蛇自己的身体,否则就游戏失败。在吃掉随机出现的" & Chr(13) & _

"果子后,蛇的身体会变长,越长难度越大。祝您好运!!", 0 + 64, "游戏规则"

End Sub

'该过程用于显示游戏开发信息

Private Sub cmdAbout_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

Beep

MsgBox "BS贪食蛇" & "(V-" & AppMajor & "" & AppMinor & "版本)" & Chr(13) & Chr(13) & _

"" & Chr(13) & Chr(13) & _

"由PigheadPrince设计制作" & Chr(13) & _

"CopyRight(C)2002,BestSoftTCG", 0, "关于本游戏"

End Sub

'该过程用于退出游戏

Private Sub cmdExit_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

Beep

msg = MsgBox("您要退出本游戏吗?", 4 + 32, "BS贪食蛇")

Select Case msg

Case 6

End

Case 7

MechkWindowButton(2)Value = 0

Exit Sub

End Select

End Sub

'该过程用于拖动窗体_(点击图标)

Private Sub imgWindowTop_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

ReleaseCapture

SendMessage Mehwnd, WM_SYSCOMMAND, SC_MOVE, 0

End Sub

'该共用过程用于处理窗体控制按钮组的相关操作_(锁定、最小化、退出)

Private Sub chkWindowButton_MouseUp(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)

If Button <> 1 Then Exit Sub

Select Case Index

Case 0 '锁定窗体

If MechkWindowButton(0)Value = 1 Then

MeimgWindowTopBorderStyle = 0

MeimgWindowTopEnabled = False

Else

MeimgWindowTopBorderStyle = 1

MeimgWindowTopEnabled = True

End If

Case 1 '最小化

MeWindowState = 1

MechkWindowButton(1)Value = 0

MeCaption = "BS贪食蛇 — (V-" & AppMajor & "" & AppMinor & "版本)"

Case 2 '退出

Beep

msg = MsgBox("您要退出本游戏吗?", 4 + 32, "BS贪食蛇")

Select Case msg

Case 6

End

Case 7

MechkWindowButton(2)Value = 0

Exit Sub

End Select

End Select

End Sub

'该过程用于设置蛇运动速度的快慢

Private Sub hsbGameSpeed_Change()

MetmrSnakeMoveInterval = MehsbGameSpeedValue

End Sub

'该过程用于通过键盘的方向键改变蛇的运动方向

Private Sub picMoveArea_KeyDown(KeyCode As Integer, Shift As Integer)

Select Case g_intDirection

Case D_UP

If KeyCode = D_DOWN Then Exit Sub

Case D_DOWN

If KeyCode = D_UP Then Exit Sub

Case D_LEFT

If KeyCode = D_RIGHT Then Exit Sub

Case D_RIGHT

If KeyCode = D_LEFT Then Exit Sub

End Select

g_intDirection = KeyCode

End Sub

'该计时循环过程用于计算游戏耗费的秒数并显示

Private Sub tmrGameTime_Timer()

g_lngGameTime = g_lngGameTime + 1

MelblGameTimeCaption = g_lngGameTime & "秒"

End Sub

'该计时循环过程用于控制蛇的行动轨迹

Private Sub tmrSnakeMove_Timer()

Dim lngSnakeX As Long, lngSnakeY As Long, lngSnakeColor As Long

Dim lngPointX As Long, lngPointY As Long, lngPointColor As Long

Randomize

MepicMoveAreaSetFocus

MepicMoveAreaCls

'确认蛇头的运动方向并获取新的位置

Select Case g_intDirection

Case D_UP '向上运动

g_udtSnake(SNAKEONE)Snake_CurX = g_udtSnake(SNAKEONE)Snake_OldX

g_udtSnake(SNAKEONE)Snake_CurY = g_udtSnake(SNAKEONE)Snake_OldY

g_udtSnake(SNAKEONE)Snake_CurY = g_udtSnake(SNAKEONE)Snake_CurY - SNAKEWIDTH

Case D_DOWN '向下运动

g_udtSnake(SNAKEONE)Snake_CurX = g_udtSnake(SNAKEONE)Snake_OldX

g_udtSnake(SNAKEONE)Snake_CurY = g_udtSnake(SNAKEONE)Snake_OldY

g_udtSnake(SNAKEONE)Snake_CurY = g_udtSnake(SNAKEONE)Snake_CurY + SNAKEWIDTH

Case D_LEFT '向左运动

g_udtSnake(SNAKEONE)Snake_CurX = g_udtSnake(SNAKEONE)Snake_OldX

g_udtSnake(SNAKEONE)Snake_CurX = g_udtSnake(SNAKEONE)Snake_CurX - SNAKEWIDTH

g_udtSnake(SNAKEONE)Snake_CurY = g_udtSnake(SNAKEONE)Snake_OldY

Case D_RIGHT '向右运动

g_udtSnake(SNAKEONE)Snake_CurX = g_udtSnake(SNAKEONE)Snake_OldX

g_udtSnake(SNAKEONE)Snake_CurX = g_udtSnake(SNAKEONE)Snake_CurX + SNAKEWIDTH

g_udtSnake(SNAKEONE)Snake_CurY = g_udtSnake(SNAKEONE)Snake_OldY

End Select

'根据新的位置绘制蛇头

lngSnakeX = g_udtSnake(SNAKEONE)Snake_CurX

lngSnakeY = g_udtSnake(SNAKEONE)Snake_CurY

lngSnakeColor = g_udtSnake(SNAKEONE)Snake_Color

MepicMoveAreaPSet (lngSnakeX, lngSnakeY), lngSnakeColor

'移动蛇身体其他部分的位置

For i = 2 To g_intSnakeLength

g_udtSnake(i)Snake_CurX = g_udtSnake(i - 1)Snake_OldX

g_udtSnake(i)Snake_CurY = g_udtSnake(i - 1)Snake_OldY

lngSnakeX = g_udtSnake(i)Snake_CurX

lngSnakeY = g_udtSnake(i)Snake_CurY

lngSnakeColor = g_udtSnake(i)Snake_Color

MepicMoveAreaPSet (lngSnakeX, lngSnakeY), lngSnakeColor

Next i

'更新蛇旧的坐标位置

For j = 1 To g_intSnakeLength

g_udtSnake(j)Snake_OldX = g_udtSnake(j)Snake_CurX

g_udtSnake(j)Snake_OldY = g_udtSnake(j)Snake_CurY

Next j

'判断蛇在移动中是否到了禁区而导致游戏失败

If m_funMoveForbiddenZone(g_udtSnake(SNAKEONE)Snake_CurX, g_udtSnake(SNAKEONE)Snake_CurY) Then

Beep

MsgBox "您的蛇移动到了禁区,游戏失败!", 0 + 16, "BS贪食蛇"

MetmrSnakeMoveEnabled = False

MetmrGameTimeEnabled = False

MepicMoveAreaVisible = False

Exit Sub

End If

'判断蛇在移动中是否碰到了自己的身体而导致游戏失败

If m_funTouchSnakeBody(g_udtSnake(SNAKEONE)Snake_CurX, g_udtSnake(SNAKEONE)Snake_CurY) Then

Beep

MsgBox "您的蛇在移动中碰到了自己的身体,游戏失败!", 0 + 16, "BS贪食蛇"

MetmrSnakeMoveEnabled = False

MetmrGameTimeEnabled = False

MepicMoveAreaVisible = False

Exit Sub

End If

'判断蛇是否吃到了果子

If m_funEatPoint(g_udtSnake(SNAKEONE)Snake_CurX, g_udtSnake(SNAKEONE)Snake_CurY) Then

'累加玩家的得分并刷新得分显示

g_intPlayerScore = g_intPlayerScore + 1

MelblYourScoreCaption = g_intPlayerScore & "分"

Call m_subAddSnake '加长蛇的身体

Call m_subGetPoint '获取下一个果子的位置和颜色

Else

'绘制果子

lngPointX = g_udtPointPoint_X

lngPointY = g_udtPointPoint_Y

lngPointColor = g_udtPointPoint_Color

MepicMoveAreaPSet (lngPointX, lngPointY), lngPointColor

End If

End Sub

'该私有子过程用于初始化游戏

Private Sub m_subGameInitialize()

Erase g_udtSnake '清空蛇的结构数组

g_intPlayerScore = 0 '清空玩家的得分

g_lngGameTime = 0 '清空游戏耗费的秒数

g_intDirection = D_DOWN '设定蛇的初始运动方向为下

g_intSnakeLength = 4 '设定蛇的初始长度

ReDim g_udtSnake(1 To g_intSnakeLength) '重新定义蛇的长度

'定义蛇头部的数据

With g_udtSnake(SNAKEONE)

Snake_OldX = 530

Snake_OldY = 530

Snake_Color = vbBlack

End With

'定义蛇身第2节的数据

With g_udtSnake(SNAKETWO)

Snake_OldX = 530

Snake_OldY = 430

Snake_Color = vbGreen

End With

'定义蛇身第3节的数据

With g_udtSnake(SNAKETHREE)

Snake_OldX = 530

Snake_OldY = 330

Snake_Color = vbYellow

End With

'定义蛇身第4节的数据

With g_udtSnake(SNAKEFOUR)

Snake_OldX = 530

Snake_OldY = 230

Snake_Color = vbRed

End With

MepicMoveAreaVisible = True

MelblYourScoreCaption = g_intPlayerScore & "分"

MelblGameTimeCaption = g_lngGameTime & "秒"

MetmrSnakeMoveInterval = MehsbGameSpeedValue

MetmrSnakeMoveEnabled = True

MetmrGameTimeEnabled = True

Call m_subGetPoint '获取第一个果子的位置和颜色

End Sub

'该私有子过程用于返回获取的果子的位置和颜色信息

Private Sub m_subGetPoint()

Dim lngRedValue As Long, lngGreenValue As Long, lngBlueValue As Long

Dim lngPointX As Long, lngPointY As Long, lngPointColor As Long

'随机获取果子的颜色

lngRedValue = Int((255 - 0 + 1) Rnd + 0)

lngGreenValue = Int((255 - 0 + 1) Rnd + 0)

lngBlueValue = Int((255 - 0 + 1) Rnd + 0)

lngPointColor = RGB(lngRedValue, lngGreenValue, lngBlueValue)

'随机获取果子的位置

lngPointX = Int((FZ_LEFT - FZ_RIGHT + 1) Rnd + FZ_RIGHT)

lngPointY = Int((FZ_TOP - FZ_BOTTOM + 1) Rnd + FZ_BOTTOM)

MePSet (lngPointX, lngPointY), lngPointColor

'设置函数返回值

With g_udtPoint

Point_X = lngPointX

Point_Y = lngPointY

Point_Color = lngPointColor

End With

End Sub

欢迎分享,转载请注明来源:品搜搜测评网

原文地址:https://pinsoso.cn/meirong/2379944.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-11-29
下一篇2023-11-29

随机推荐

  • 大学生电商创业?

    我们一起来分析一下优劣势以及相应的解决方案:优势:1 熟练掌握互联网技术:大学生们在成长过程中接受到更多的互联网知识和技术培训,能够更好地利用网络资源开展电商创业项目。2 具备创意意识:大学生们常常有着敏锐的创意意识,能够思考出一些新颖的商

    2024-04-15
    61100
  • “山寨”是什么意思?

    [编辑本段]山寨古义山寨拼音:shān zhài山寨亦作“ 山砦 ”。 1筑有栅栏等防守工事的山庄。 宋 李心传 《建炎以来朝野杂记·龙州蕃部寇边》:“王钺又请於其前筑水礶山寨,以为戍守之所,朝廷皆从之。”《宋史·岳飞传》:“飞

    2024-04-15
    61600
  • 精华露和精华液的区别

    精华露和精华液是我们常见的美容护肤产品,它们都是一种高浓度的保养品,含有多种活性成分,能够深层滋养肌肤。虽然两者名称相似,但其实它们有着不同的特点和使用方法。从质地上来看,精华露通常是半透明的液体状质地,较为清爽易吸收;而精华液则比较浓稠,

    2024-04-15
    59500
  • 口碑最好十大沐浴露

    口碑最好十大沐浴露有:多芬、强生婴儿、力士、舒肤佳、玉兰油、六神、妮维雅、凌仕、威露士、阿迪达斯。1、多芬:多芬创立于1957年,是全球著名的女性品牌,隶属于联合利华旗下。多芬是秀发和肌肤理护专家,主要产品是沐浴乳、洗发水及护发素。2、强生

    2024-04-15
    44000
  • 夏日好用又平价的水乳有哪些 适合夏天用的水乳

    一到夏天就不想往脸上抹东西了,面霜粘腻的感触真心不舒服,打败你的不是天真,是天真热,所以这时候就需要购买一款适合夏天使用的水乳了。今天我就为大家分享几款平价又好用的水乳吧,清爽不粘腻,非常适合夏天使用哦。1、芙丽芳丝水乳这是一款对敏感肌和孕

    2024-04-15
    37400
  • 伊思红参蜗牛霜怎么用,伊思红参蜗牛霜使用方法

    its skin伊思红参蜗牛霜是目前市场非常受欢迎的产品这一,虽然说通常面霜在使用上面并没有什么太需要注意的,不过品牌的不同也会有一些细节上的差别,以下我将为大家说明its skin伊思红参蜗牛霜的用法。伊思红参蜗牛霜怎么用1、彻底

    2024-04-15
    39800
  • sk2套装有两瓶水,一瓶乳液怎么使用

    按照你的描述,推测这个套装里的产品应该是:sk2清莹露、神仙水(sk2面部精华液)、sk2乳液。一、使用顺序:先是清莹露,再用神仙水,最后用乳液。二、使用方法1、清莹露的主要功能是软化肌肤肤质、二次清洁、促进后续护肤品吸收;取适量本品于化妆

    2024-04-15
    38700

发表评论

登录后才能评论
保存