📄 form1.frm
字号:
VERSION 5.00
Object = "{27395F88-0C0C-101B-A3C9-08002B2F49FB}#1.1#0"; "PICCLP32.OCX"
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 3090
ClientLeft = 60
ClientTop = 450
ClientWidth = 4680
LinkTopic = "Form1"
ScaleHeight = 11010
ScaleWidth = 15240
StartUpPosition = 3 '窗口缺省
Begin VB.PictureBox Picture1
Height = 495
Left = 3360
ScaleHeight = 435
ScaleWidth = 1155
TabIndex = 3
Top = 240
Width = 1215
End
Begin VB.CommandButton Command1
Caption = "开始"
Height = 375
Left = 1080
TabIndex = 0
Top = 9360
Width = 975
End
Begin PicClip.PictureClip PictureClip1
Left = 4080
Top = 9840
_ExtentX = 21167
_ExtentY = 15875
_Version = 393216
Rows = 3
Cols = 3
Picture = "Form1.frx":0000
End
Begin VB.Image Image1
Height = 2665
Index = 8
Left = 9000
Top = 6330
Width = 4005
End
Begin VB.Image Image1
Height = 2665
Index = 7
Left = 5000
Top = 6330
Width = 4005
End
Begin VB.Image Image1
Height = 2670
Index = 6
Left = 1005
Top = 6330
Width = 4005
End
Begin VB.Image Image1
Height = 2665
Index = 5
Left = 9000
Top = 3665
Width = 4005
End
Begin VB.Image Image1
Height = 2665
Index = 4
Left = 5000
Top = 3665
Width = 4005
End
Begin VB.Image Image1
Height = 2665
Index = 3
Left = 1000
Top = 3665
Width = 4005
End
Begin VB.Image Image1
Height = 2665
Index = 2
Left = 9000
Top = 1000
Width = 4005
End
Begin VB.Image Image1
Height = 2665
Index = 1
Left = 5000
Top = 1000
Width = 4005
End
Begin VB.Image Image1
Height = 2665
Index = 0
Left = 1000
Top = 1000
Width = 4005
End
Begin VB.Label Label2
Caption = "0"
Height = 255
Left = 3840
TabIndex = 2
Top = 9480
Width = 735
End
Begin VB.Label Label1
Caption = "步数"
Height = 375
Left = 2760
TabIndex = 1
Top = 9360
Width = 615
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim i As Integer '定义循环变量
Dim j As Integer
Dim step As Integer
Dim x(8) As Integer '定义一个数组,用来存放随机编号
Private Sub Command1_Click()
init '初始化游戏
Command1.Enabled = False '使开始按钮失效
End Sub
Sub init() '初始化游戏子程序
For i = 0 To 7 '随机产生不重复的8个编号(从0到7)
a0: x(i) = Int(Rnd * 8)
For j = 0 To i - 1
If x(i) = x(j) Then GoTo a0
Next
Next
For i = 0 To 7
Image1(i).Enabled = True '使Image1响应鼠标事件
Image1(x(i)).Picture = PictureClip1.GraphicCell(i) '让图片的8个单元分别赋予 8个Image控件
Next
Image1(8).Picture = LoadPicture("") '空位用于移动图片
End Sub
Private Sub Form_Load()
Randomize
End Sub
Private Sub Image1_Click(Index As Integer) '注意索引值的运用
Select Case Index Mod 3 '把9个Image控件分成三列
Case 0 '当鼠标点击第1列时
If Image1(Index + 1).Picture = LoadPicture("") Then '判断右边是否为空
Image1(Index + 1).Picture = Image1(Index).Picture '交换图片
Image1(Index).Picture = LoadPicture("")
win '测试是否拼图成功
End If
Case 1 '当鼠标点击第2列时
If Image1(Index - 1).Picture = LoadPicture("") Then '判断左边是否为空
Image1(Index - 1).Picture = Image1(Index).Picture
Image1(Index).Picture = LoadPicture("")
win
End If
'[NextPage]
If Image1(Index + 1).Picture = LoadPicture("") Then '判断右边是否为空
Image1(Index + 1).Picture = Image1(Index).Picture
Image1(Index).Picture = LoadPicture("")
win
End If
Case 2 '当鼠标点击第3列时
If Image1(Index - 1).Picture = LoadPicture("") Then '判断左边是否为空
Image1(Index - 1).Picture = Image1(Index).Picture
Image1(Index).Picture = LoadPicture("")
win
End If
End Select
Select Case Index \ 3 '把9个Image控件分成三行
Case 0 '当鼠标点击第1行时
If Image1(Index + 3).Picture = LoadPicture("") Then '判断下边是否为空
Image1(Index + 3).Picture = Image1(Index).Picture
Image1(Index).Picture = LoadPicture("")
win
End If
Case 1 '当鼠标点击第2行时
If Image1(Index - 3).Picture = LoadPicture("") Then '判断上边是否为空
Image1(Index - 3).Picture = Image1(Index).Picture
Image1(Index).Picture = LoadPicture("")
win
End If
If Image1(Index + 3).Picture = LoadPicture("") Then '判断下边是否为空
Image1(Index + 3).Picture = Image1(Index).Picture
Image1(Index).Picture = LoadPicture("")
win
End If
Case 2 '当鼠标点击第3行时
If Image1(Index - 3).Picture = LoadPicture("") Then '判断上边是否为空
Image1(Index - 3).Picture = Image1(Index).Picture
Image1(Index).Picture = LoadPicture("")
win
End If
End Select
End Sub
Sub win() '测试是否拼图成功的子程序
Dim num As Integer
step = step + 1 '步数加1
Label2.Caption = step
For i = 0 To 8 '判断图块是否全部就位
If Image1(i).Picture = PictureClip1.GraphicCell(i) Then num = num + 1
Next
If num = 8 Then
MsgBox "你真棒!"
For i = 0 To 8
Image1(i).Enabled = False '使之不响应鼠标事件
Next
Command1.Enabled = True '恢复命令按钮
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -