1个回答
2013-07-19
展开全部
用PaintPicture来将一个大图片的分块显示在几个不同的小Picture控件里,事先给让这几个Picture控件随机的两两掉换位置N次,这样就把原图打乱了。判断是否拼图成功就判断小图片的位置是否回到了原来初始位置,如果所有的小图片的位置都恢复正确那么拼图成功,具体的你应该会做了。]
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
Private Sub Form_Load()�
Randomize'起始随机数产生器
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 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
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
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
Private Sub Form_Load()�
Randomize'起始随机数产生器
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 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
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
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询