📄 youxi.frm
字号:
VERSION 5.00
Begin VB.Form MainFrm
BackColor = &H00FFC0C0&
BorderStyle = 1 'Fixed Single
Caption = "华容道"
ClientHeight = 6270
ClientLeft = 45
ClientTop = 330
ClientWidth = 7140
BeginProperty Font
Name = "幼圆"
Size = 12
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00FF0000&
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 6270
ScaleWidth = 7140
StartUpPosition = 2 '屏幕中心
Begin VB.TextBox Text1
BackColor = &H00C0C0FF&
Enabled = 0 'False
ForeColor = &H00FF0000&
Height = 2415
Left = 5040
Locked = -1 'True
MultiLine = -1 'True
TabIndex = 7
Text = "youxi.frx":0000
Top = 1680
Width = 1695
End
Begin VB.Timer TmrGameTime
Enabled = 0 'False
Interval = 1000
Left = 4680
Top = 5520
End
Begin VB.CommandButton CmdExit
Caption = "退出游戏"
Height = 495
Left = 5280
TabIndex = 3
Top = 5640
Width = 1335
End
Begin VB.CommandButton CmdStart
Caption = "开始游戏"
Height = 495
Left = 5280
TabIndex = 2
Top = 5040
Width = 1335
End
Begin VB.PictureBox PicFrame
BackColor = &H00FF0000&
BeginProperty Font
Name = "宋体"
Size = 9
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 5055
Left = 480
ScaleHeight = 4995
ScaleWidth = 4035
TabIndex = 0
Top = 720
Width = 4095
Begin VB.Image imgSoldier
Enabled = 0 'False
Height = 1005
Index = 2
Left = 2000
Picture = "youxi.frx":0071
Stretch = -1 'True
Tag = "8"
Top = 3000
Width = 1005
End
Begin VB.Image imgSoldier
Enabled = 0 'False
Height = 1005
Index = 1
Left = 1000
Picture = "youxi.frx":16CB
Stretch = -1 'True
Tag = "7"
Top = 3000
Width = 1005
End
Begin VB.Image imgSoldier
Enabled = 0 'False
Height = 1005
Index = 4
Left = 1005
Picture = "youxi.frx":2D25
Stretch = -1 'True
Tag = "5"
Top = 2000
Width = 1005
End
Begin VB.Image imgSoldier
Enabled = 0 'False
Height = 1005
Index = 5
Left = 2000
Picture = "youxi.frx":437F
Stretch = -1 'True
Tag = "6"
Top = 2000
Width = 1005
End
Begin VB.Image imgCaocao
Enabled = 0 'False
Height = 2000
Left = 1000
Picture = "youxi.frx":59D9
Stretch = -1 'True
Tag = "0"
Top = 0
Width = 2000
End
Begin VB.Image imgSoldier
Enabled = 0 'False
Height = 1005
Index = 0
Left = 0
Picture = "youxi.frx":9574
Stretch = -1 'True
Tag = "10"
Top = 3960
Width = 1005
End
Begin VB.Image imgSoldier
Enabled = 0 'False
Height = 1000
Index = 3
Left = 3000
Picture = "youxi.frx":ABCE
Stretch = -1 'True
Tag = "9"
Top = 4000
Width = 1000
End
Begin VB.Image imgGeneral
Enabled = 0 'False
Height = 2000
Index = 0
Left = 0
Picture = "youxi.frx":C228
Stretch = -1 'True
Tag = "1"
Top = 0
Width = 1000
End
Begin VB.Image imgGeneral
Enabled = 0 'False
Height = 2000
Index = 1
Left = 3000
Picture = "youxi.frx":E823
Stretch = -1 'True
Tag = "2"
Top = 0
Width = 1000
End
Begin VB.Image imgGeneral
Enabled = 0 'False
Height = 2000
Index = 2
Left = 0
Picture = "youxi.frx":10E1E
Stretch = -1 'True
Tag = "3"
Top = 2000
Width = 1000
End
Begin VB.Image imgGeneral
Enabled = 0 'False
Height = 2000
Index = 3
Left = 3000
Picture = "youxi.frx":13419
Stretch = -1 'True
Tag = "4"
Top = 2000
Width = 1000
End
End
Begin VB.Label Label2
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "游戏规则"
Height = 240
Left = 5280
TabIndex = 6
Top = 1200
Width = 1035
End
Begin VB.Label Label3
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "出 口"
Height = 240
Left = 1920
TabIndex = 5
Top = 5880
Width = 795
End
Begin VB.Label LblTime
Alignment = 2 'Center
AutoSize = -1 'True
BackColor = &H00FFC0C0&
BorderStyle = 1 'Fixed Single
Caption = "所花时间:0秒"
Height = 300
Left = 5040
TabIndex = 4
Top = 4440
Width = 1740
End
Begin VB.Label Label1
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "华容道"
BeginProperty Font
Name = "华文行楷"
Size = 36
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H0000FFFF&
Height = 765
Left = 1440
TabIndex = 1
Top = 0
Width = 2220
End
End
Attribute VB_Name = "MainFrm"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim M_DragX, M_DragY As Integer '鼠标按下时鼠标位置(相对于Image控件)
Dim Img_OldX, Img_OldY As Integer '鼠标按下时Image控件的左上角位置
Dim Img_NewX, Img_NewY As Integer '鼠标松开时Image控件的左上角位置
Dim m_lngTime As Long '游戏时间
Private Sub cmdExit_Click()
End
End Sub
Private Sub cmdStart_Click()
Dim i As Integer, j As Integer
CmdStart.Caption = "重新开始" '恢复计时器重新计时
TmrGameTime.Enabled = True
m_lngTime = 0
For i = 0 To 3 '让图片可以拖动
imgGeneral(i).Enabled = True
Next
For j = 0 To 5
imgSoldier(j).Enabled = True
Next
imgCaocao.Enabled = True
End Sub
Private Sub imgCaocao_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
imgCaocao.Drag vbBeginDrag '鼠标按下时,开始拖动
M_DragX = X '记录鼠标在图片内的位置
M_DragY = Y
Img_OldX = imgCaocao.Left '记录图片的原始位置
Img_OldY = imgCaocao.Top
End Sub
Private Sub imgGeneral_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
imgGeneral(Index).Drag vbBeginDrag
M_DragX = X
M_DragY = Y
Img_OldX = imgGeneral(Index).Left
Img_OldY = imgGeneral(Index).Top
End Sub
Private Sub imgSoldier_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
imgSoldier(Index).Drag vbBeginDrag
M_DragX = X
M_DragY = Y
Img_OldX = imgSoldier(Index).Left
Img_OldY = imgSoldier(Index).Top
End Sub
'拖动图片操作将要完成时发生的动作,source参数指正在被拖动的对象
Private Sub picFrame_DragDrop(Source As Control, X As Single, Y As Single)
Source.Move (X - M_DragX), (Y - M_DragY) '拖动结束后先把图片控件移动到位
Img_NewX = Source.Left '记录左上角位置
Img_NewY = Source.Top
If (Abs(Img_NewX - Img_OldX) > Abs(Img_NewY - Img_OldY)) Then '判断移动方向,取绝对值
If (Img_NewX - Img_OldX > 0) Then
Source.Move Img_OldX + 1000, Img_OldY '向右移动
Else
Source.Move Img_OldX - 1000, Img_OldY '向左移动
End If
Else
If (Img_NewY - Img_OldY > 0) Then '向下移动
Source.Move Img_OldX, Img_OldY + 1000
Else
Source.Move Img_OldX, Img_OldY - 1000 '向上移动
End If
End If
Dim intCenterX, intCenterY As Integer '判断是否有重叠
intCenterX = Source.Left + Source.Width / 2 '取被拖动控件中点,判断是否落在其它图片内部
intCenterY = Source.Top + Source.Height / 2
If (Source.Tag <> imgCaocao.Tag) Then
If (PointInRect(imgCaocao, intCenterX, intCenterY)) Then
Source.Move Img_OldX, Img_OldY
End If
End If
Dim i As Integer, j As Integer
For i = 0 To 3
If (Source.Tag <> imgGeneral(i).Tag) Then
If (PointInRect(imgGeneral(i), intCenterX, intCenterY)) Then
Source.Move Img_OldX, Img_OldY
End If
End If
Next
For j = 0 To 5
If (Source.Tag <> imgSoldier(j).Tag) Then
If (PointInRect(imgSoldier(j), intCenterX, intCenterY)) Then
Source.Move Img_OldX, Img_OldY
End If
End If
Next
If (imgCaocao.Left = 1000 And imgCaocao.Top = 3000) Then
'游戏成功,曹操逃出华容道
MsgBox "你胜利了!你真行!,所花时间为 " & CStr(m_lngTime) & " 秒", vbOKOnly, "恭喜恭喜"
TmrGameTime.Enabled = False '停止计时
imgGeneral(0).Enabled = False
imgGeneral(1).Enabled = False
imgGeneral(2).Enabled = False
imgGeneral(3).Enabled = False
imgSoldier(0).Enabled = False
imgSoldier(1).Enabled = False
imgSoldier(2).Enabled = False
imgSoldier(3).Enabled = False
imgSoldier(4).Enabled = False
imgSoldier(5).Enabled = False
imgCaocao.Enabled = False
End If
End Sub
Private Function PointInRect(Image As Control, ByVal X As Integer, ByVal Y As Integer) As Boolean
'判断一个点是否在Image控件内部
If (X >= Image.Left And X <= (Image.Left + Image.Width) And Y >= Image.Top And Y <= (Image.Top + Image.Height)) Then
PointInRect = True
Else
PointInRect = False
End If
End Function
Private Sub tmrGameTime_Timer()
m_lngTime = m_lngTime + 1 '设置游戏时间标签
Dim strTime As String
strTime = "所花时间:" & CStr(m_lngTime) & " 秒"
LblTime.Caption = strTime
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -