1.VBè´ªåè代ç
VBè´ªåè代ç
'å®ä¹èçè¿å¨é度æ举å¼
Private Enum tpsSpeed
QUICKLY = 0
SLOWLY = 1
End Enum
'å®ä¹èçè¿å¨æ¹åæ举å¼
Private Enum tpsDirection
D_UP =
D_DOWN =
D_LEFT =
D_RIGHT =
End Enum
'å®ä¹è¿å¨åºå4个ç¦åºçæ举å¼
Private Enum tpsForbiddenZone
FZ_TOP =
FZ_BOTTOM =
FZ_LEFT =
FZ_RIGHT =
End Enum
'å®ä¹è头å身ä½åå§åæ°æ举å¼
Private Enum tpsSnake
SNAKEONE = 1
SNAKETWO = 2
SNAKETHREE = 3
SNAKEFOUR = 4
End Enum
'å®ä¹è宽度ç常é
Private Const SNAKEWIDTH As Integer =
'该è¿ç¨ç¨äºæ¾ç¤ºæ¸¸æä¿¡æ¯
Private Sub Form_Load()
Me.Show
Me.lblTitle = "BSè´ªé£è â (çæ¬ " & App.Major & "." & App.Minor & "." & App.Revision & ")"
Me.Caption = Me.lblTitle.Caption
frmSplash.Show 1
End Sub
'该è¿ç¨ç¨äºä½¿çªä½æ¢å¤åå§å¤§å°
Private Sub Form_Resize()
If Me.WindowState <> 1 The贪食棋牌大厅源码n
Me.Caption = ""
Me.Height = 'çªä½é«åº¦ä¸º ç¼
Me.Width = 'çªä½å®½åº¦ä¸º ç¼
Me.Left = (Screen.Width - Width) \ 2
Me.Top = (Screen.Height - 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 + , "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 Me.chkPause.Caption = "æå游æ(&P)" Then
Me.tmrSnakeMove.Enabled = False
Me.tmrGameTime.Enabled = False
Me.picMoveArea.Enabled = False
Me.lblPauseLab.Visible = True
Me.chkPause.Caption = "继ç»æ¸¸æ(&R)"
Else
Me.tmrSnakeMove.Enabled = True
Me.tmrGameTime.Enabled = True
Me.picMoveArea.Enabled = True
Me.lblPauseLab.Visible = False
Me.chkPause.Caption = "æå游æ(&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() & _
"ä¸ç4个æ¹åé®æ¥æ§å¶èçè¿å¨æ¹åãå¨è¿å¨è¿ç¨ä¸è" & Chr() & _
"ä¸è½åéï¼èç头é¨ä¹ä¸è½æ¥è§¦å°è¿å¨åºåç边线以å¤" & Chr() & _
"åèèªå·±ç身ä½ï¼å¦å就游æ失败ãå¨åæéæºåºç°ç" & Chr() & _
"æååï¼èç身ä½ä¼åé¿ï¼è¶é¿é¾åº¦è¶å¤§ãç¥æ¨å¥½è¿ï¼ï¼", 0 + , "游æè§å"
End Sub
'该è¿ç¨ç¨äºæ¾ç¤ºæ¸¸æå¼åä¿¡æ¯
Private Sub cmdAbout_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Beep
MsgBox "BSè´ªé£è" & "(V-" & App.Major & "." & App.Minor & "çæ¬)" & Chr() & Chr() & _
"" & Chr() & Chr() & _
"ç±PigheadPrince设计å¶ä½" & Chr() & _
"CopyRight(C),BestSoft.TCG", 0, "å ³äºæ¬æ¸¸æ"
End Sub
'该è¿ç¨ç¨äºéåºæ¸¸æ
Private Sub cmdExit_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Beep
msg = MsgBox("æ¨è¦éåºæ¬æ¸¸æåï¼", 4 + , "BSè´ªé£è")
Select Case msg
Case 6
End
Case 7
Me.chkWindowButton(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 Me.hwnd, 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 Me.chkWindowButton(0).Value = 1 Then
Me.imgWindowTop.BorderStyle = 0
Me.imgWindowTop.Enabled = False
Else
Me.imgWindowTop.BorderStyle = 1
Me.imgWindowTop.Enabled = True
End If
Case 1 'æå°å
Me.WindowState = 1
Me.chkWindowButton(1).Value = 0
Me.Caption = "BSè´ªé£è â (V-" & App.Major & "." & App.Minor & "çæ¬)"
Case 2 'éåº
Beep
msg = MsgBox("æ¨è¦éåºæ¬æ¸¸æåï¼", 4 + , "BSè´ªé£è")
Select Case msg
Case 6
End
Case 7
Me.chkWindowButton(2).Value = 0
Exit Sub
End Select
End Select
End Sub
'该è¿ç¨ç¨äºè®¾ç½®èè¿å¨é度çå¿«æ ¢
Private Sub hsbGameSpeed_Change()
Me.tmrSnakeMove.Interval = Me.hsbGameSpeed.Value
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
Me.lblGameTime.Caption = 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
Me.picMoveArea.SetFocus
Me.picMoveArea.Cls
'确认è头çè¿å¨æ¹å并è·åæ°çä½ç½®
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
Me.picMoveArea.PSet (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
Me.picMoveArea.PSet (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 + , "BSè´ªé£è"
Me.tmrSnakeMove.Enabled = False
Me.tmrGameTime.Enabled = False
Me.picMoveArea.Visible = False
Exit Sub
End If
'å¤æèå¨ç§»å¨ä¸æ¯å¦ç¢°å°äºèªå·±ç身ä½è导è´æ¸¸æ失败
If m_funTouchSnakeBody(g_udtSnake(SNAKEONE).Snake_CurX, g_udtSnake(SNAKEONE).Snake_CurY) Then
Beep
MsgBox "æ¨çèå¨ç§»å¨ä¸ç¢°å°äºèªå·±ç身ä½ï¼æ¸¸æ失败ï¼", 0 + , "BSè´ªé£è"
Me.tmrSnakeMove.Enabled = False
Me.tmrGameTime.Enabled = False
Me.picMoveArea.Visible = False
Exit Sub
End If
'å¤æèæ¯å¦åå°äºæå
If m_funEatPoint(g_udtSnake(SNAKEONE).Snake_CurX, g_udtSnake(SNAKEONE).Snake_CurY) Then
'ç´¯å ç©å®¶çå¾å并å·æ°å¾åæ¾ç¤º
g_intPlayerScore = g_intPlayerScore + 1
Me.lblYourScore.Caption = g_intPlayerScore & "å"
Call m_subAddSnake 'å é¿èç身ä½
Call m_subGetPoint 'è·åä¸ä¸ä¸ªæåçä½ç½®åé¢è²
Else
'ç»å¶æå
lngPointX = g_udtPoint.Point_X
lngPointY = g_udtPoint.Point_Y
lngPointColor = g_udtPoint.Point_Color
Me.picMoveArea.PSet (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 =
.Snake_OldY =
.Snake_Color = vbBlack
End With
'å®ä¹è身第2èçæ°æ®
With g_udtSnake(SNAKETWO)
.Snake_OldX =
.Snake_OldY =
.Snake_Color = vbGreen
End With
'å®ä¹è身第3èçæ°æ®
With g_udtSnake(SNAKETHREE)
.Snake_OldX =
.Snake_OldY =
.Snake_Color = vbYellow
End With
'å®ä¹è身第4èçæ°æ®
With g_udtSnake(SNAKEFOUR)
.Snake_OldX =
.Snake_OldY =
.Snake_Color = vbRed
End With
Me.picMoveArea.Visible = True
Me.lblYourScore.Caption = g_intPlayerScore & "å"
Me.lblGameTime.Caption = g_lngGameTime & "ç§"
Me.tmrSnakeMove.Interval = Me.hsbGameSpeed.Value
Me.tmrSnakeMove.Enabled = True
Me.tmrGameTime.Enabled = 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(( - 0 + 1) * Rnd + 0)
lngGreenValue = Int(( - 0 + 1) * Rnd + 0)
lngBlueValue = Int(( - 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)
Me.PSet (lngPointX, lngPointY), lngPointColor
'设置å½æ°è¿åå¼
With g_udtPoint
.Point_X = lngPointX
.Point_Y = lngPointY
.Point_Color = lngPointColor
End With
End Sub
'该ç§æåè¿ç¨ç¨äºå é¿èç身ä½
Private Sub m_subAddSnake()
Dim udtSnakeTemp() As Snake
Dim lngSnakeX As Long, lngSnakeY As Long, lngSnakeColor As Long
'å¤ä»½èåå 身ä½çæ°æ®å¹¶ä½¿èç身ä½å é¿
ReDim udtSnakeTemp(1 To g_intSnakeLength)
For k = 1 To g_intSnakeLength
With udtSnakeTemp(k)
.Snake_CurX = g_udtSnake(k).Snake_CurX
.Snake_CurY = g_udtSnake(k).Snake_CurY
.Snake_OldX = g_udtSnake(k).Snake_OldX
.Snake_OldY = g_udtSnake(k).Snake_OldY
.Snake_Color = g_udtSnake(k).Snake_Color
End With
Next k
g_intSnakeLength = g_intSnakeLength + 1
ReDim g_udtSnake(g_intSnakeLength)
'å°å¤ä»½è身ä½çæ°æ®è¿åå°å é¿çè身æ°ç»ä¸
For l = 1 To g_intSnakeLength - 1
With g_udtSnake(l)
.Snake_CurX = udtSnakeTemp(l).Snake_CurX
.Snake_CurY = udtSnakeTemp(l).Snake_CurY
.Snake_OldX = udtSnakeTemp(l).Snake_OldX
.Snake_OldY = udtSnakeTemp(l).Snake_OldY
.Snake_Color = udtSnakeTemp(l).Snake_Color
End With
Next l
'åå ¥æ°å å ¥ç身ä½æ°æ®
Select Case g_intDirection
Case D_UP
With g_udtSnake(g_intSnakeLength)
.Snake_OldX = g_udtSnake(g_intSnakeLength - 1).Snake_CurX + SNAKEWIDTH
.Snake_OldY = g_udtSnake(g_intSnakeLength - 1).Snake_CurY
.Snake_Color = g_udtPoint.Point_Color
End With
Case D_DOWN
With g_udtSnake(g_intSnakeLength)
.Snake_OldX = g_udtSnake(g_intSnakeLength - 1).Snake_CurX - SNAKEWIDTH
.Snake_OldY = g_udtSnake(g_intSnakeLength - 1).Snake_CurY
.Snake_Color = g_udtPoint.Point_Color
End With
Case D_LEFT
With g_udtSnake(g_intSnakeLength)
.Snake_OldX = g_udtSnake(g_intSnakeLength - 1).Snake_CurX
.Snake_OldY = g_udtSnake(g_intSnakeLength - 1).Snake_CurY + SNAKEWIDTH
.Snake_Color = g_udtPoint.Point_Color
End With
Case D_RIGHT
With g_udtSnake(g_intSnakeLength)
.Snake_OldX = g_udtSnake(g_intSnakeLength - 1).Snake_CurX
.Snake_OldY = g_udtSnake(g_intSnakeLength - 1).Snake_CurY - SNAKEWIDTH
.Snake_Color = g_udtPoint.Point_Color
End With
End Select
lngSnakeX = g_udtSnake(g_intSnakeLength).Snake_CurX
lngSnakeY = g_udtSnake(g_intSnakeLength).Snake_CurY
lngSnakeColor = g_udtSnake(g_intSnakeLength).Snake_Color
Me.picMoveArea.PSet (lngSnakeX, lngSnakeY), lngSnakeColor
End Sub
'该èªå®ä¹å½æ°ç¨äºè¿åè¿å¨çèæ¯å¦å°è¾¾ç¦åºè导è´æ¸¸æ失败
Private Function m_funMoveForbiddenZone(SnakeX As Long, SnakeY As Long) As Boolean
If (SnakeX >= FZ_LEFT And SnakeX <= FZ_RIGHT) And (SnakeY >= FZ_TOP And SnakeY <= FZ_BOTTOM) Then
m_funMoveForbiddenZone = False
Else
m_funMoveForbiddenZone = True
End If
End Function
'该èªå®ä¹å½æ°ç¨äºè¿åè¿å¨çèæ¯å¦ç¢°å°èªå·±ç身ä½è导è´æ¸¸æ失败
Private Function m_funTouchSnakeBody(SnakeX As Long, SnakeY As Long) As Boolean
For m = 2 To g_intSnakeLength
If SnakeX = g_udtSnake(m).Snake_CurX And SnakeY = g_udtSnake(m).Snake_CurY Then
m_funTouchSnakeBody = True
Exit For
Else
m_funTouchSnakeBody = False
End If
Next m
End Function
'该èªå®ä¹å½æ°ç¨äºè¿åè¿å¨çèæ¯å¦åå°äºæå
Private Function m_funEatPoint(SnakeX As Long, SnakeY As Long) As Boolean
If Abs(SnakeX - g_udtPoint.Point_X) <= SNAKEWIDTH And Abs(SnakeY - g_udtPoint.Point_Y) <= SNAKEWIDTH Then
m_funEatPoint = True
Else
m_funEatPoint = False
End If
End Function
'ï¼APIå½æ°è°ç¨è¿ç¨_ç¨ä»¥å®ç°æ æ é¢çªä½çæå¨æä½ï¼---------------------------------
'RleaseCaptureå½æ°ç¨ä»¥éæ¾é¼ æ æè·
Public Declare Function ReleaseCapture Lib "user" () As Long
'SendMessageå½æ°ç¨ä½åWindowsåé移å¨çªä½çæ¶æ¯
Public Declare Function SendMessage Lib "user" Alias "SendMessageA" (ByVal hwnd As _
Long, ByVal wMsg As Long, ByVal wParam As Long, IParam As Any) As Long
Public Const WM_SYSCOMMAND = &H '声æåWindowsåéæ¶æ¯ç常é
Public Const SC_MOVE = &HF '声ææ§å¶ç§»å¨çªä½å¸¸é
'ï¼æ¸¸æåé声æé¨åï¼-------------------------------------------------------------
'å®ä¹èçæ°æ®ç±»åç»æ
Public Type Snake
Snake_OldX As Long
Snake_OldY As Long
Snake_CurX As Long
Snake_CurY As Long
Snake_Color As Long
End Type
'å®ä¹æåçæ°æ®ç±»åç»æ
Public Type Point
Point_X As Long
Point_Y As Long
Point_Color As Long
End Type
'å®ä¹èçå¨ææ°ç»
Public g_udtSnake() As Snake
'å®ä¹æå
Public g_udtPoint As Point
'å®ä¹èçé¿åº¦
Public g_intSnakeLength As Integer
'å®ä¹èçé¢è²
Public g_lngSnakeColor As Long
'å®ä¹èçè¿å¨æ¹å
Public g_intDirection As Integer
'å®ä¹ç©å®¶çå¾å
Public g_intPlayerScore As Integer
'å®ä¹æ¸¸æèè´¹çç§æ°
Public g_lngGameTime As Long