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
他说我没定义 怎么定义啊 具体方法!!!
在窗体上画好一个Image1后,选中,复制,粘贴,点击“是”,再粘贴7次,拖到要的地方
数组x(i)是否定义?dim x(8)