我想做一個點了會移動9格拼圖..現在已經可以開始玩了(每次出現可隨機排列...點了可正常移動..)..只差最後完成時按下按鈕讓電腦能出現過關訊號....我用FOR NEXT迴圈逐一檢查在各位置的PIC BOX 是否為正確圖片(寫在Private Sub Command1_Click())中...但是不知道為什麼不行..能不能請你指點指點...謝謝謝謝...感激感激..^_______^..
Dim i, a, p, q, t, x1, y1 As Integer
Dim i0, i1, i2, i3, i4, i5, i6, i7 As Integer
Dim u As Boolean
Dim x(7) As Integer
..就是底下這一段
Private Sub Command1_Click()
For i0 = 0 To 7
If (Pic2(i0).Left = 0) And (Pic2(i0).Top = 0) And (Pic2(i0)=LoadPicture (A"\1. 1.jpg")) Then
For i1 = 0 To 7
If (Pic2(i1).Left = 1800) And (Pic2(i1).Top = 0) And (Pic2(i1) = LoadPicture("A:\1. 2.jpg")) Then
For i2 = 0 To 7
If (Pic2(i2).Left = 3600) And (Pic2(i2).Top = 0) And (Pic2(i2) = LoadPicture = ("A:\1. 3.jpg")) Then
For i3 = 0 To 7
If (Pic2(i3).Left = 1800) And (Pic2(i3).Top = 2040) And (Pic2(i3) = LoadPicture("A:\1. 4.jpg")) Then
For i4 = 0 To 7
If (Pic2(i4).Left = 3600) And (Pic2(i4).Top = 2040) And (Pic2(i4) = LoadPicture("A:\1. 5.jpg")) Then
For i5 = 0 To 7
If (Pic2(i5).Left = 0) And (Pic2(i5).Top = 4080) And (Pic2(i5) = LoadPicture("A:\1. 6.jpg")) Then
For i6 = 0 To 7
If (Pic2(i6).Left = 1800) And (Pic2(i6).Top = 4080) And (Pic2(i6) = LoadPicture("A:\1. 7.jpg")) Then
For i7 = 0 To 7
If (Pic2(i7).Left = 3600) And (Pic2(i7).Top = 4080) And (Pic2(i7) = LoadPicture("A:\1. 8.jpg")) Then
MsgBox ("恭喜妳...妳過關囉..")
End If
Next
End If
Next
End If
Next
End If
Next
End If
Next
End If
Next
End If
Next
End If
Next
End Sub
Private Sub Form_Load()
u = True
Dim i, a, p, q, t As Integer
Dim x(7) As Integer
Dim site As String
q = 0
For a = 0 To 7
Randomize
i = Int(Rnd() * 8) + 1
x(a) = i
Next
While q < 500
For a = 0 To 7
For p = 0 To 7
If x(a) = x(p) And (a > p Or a < p) Then
i = Int(Rnd() * 8) + 1
x(a) = i
End If
Next
Next
q = q + 1
Wend
For a = 0 To 7
site = ("A:\1." & Str(x(a)) & ".jpg")
Pic2(a) = LoadPicture(site)
Next
Lbl.Caption = 0
End Sub
圖片點了會移動的方式..在下面..
Private Sub Pic2_Click(Index As Integer)
t = Index
If Pic2(t).Top > PicSpace.Top Or Pic2(t).Top < PicSpace.Top Then
If Abs(Pic2(t).Left - PicSpace.Left) < 1800 And Abs(Pic2(t).Top - PicSpace.Top) <= 2040 Then
x1 = Pic2(t).Left
y1 = Pic2(t).Top
Pic2(t).Left = PicSpace.Left
Pic2(t).Top = PicSpace.Top
PicSpace.Left = x1
PicSpace.Top = y1
Lbl.Caption = Lbl.Caption + 1
End If
End If
If Pic2(t).Left > PicSpace.Left Or Pic2(t).Left < PicSpace.Left Then
If Abs(Pic2(t).Left - PicSpace.Left) <= 1800 And Abs(Pic2(t).Top - PicSpace.Top) < 2040 Then
x1 = Pic2(t).Left
y1 = Pic2(t).Top
Pic2(t).Left = PicSpace.Left
Pic2(t).Top = PicSpace.Top
PicSpace.Left = x1
PicSpace.Top = y1
Lbl.Caption = Lbl.Caption + 1
End If
End If
End Sub