vb拼图游戏,求大神详解
本帖最后由 bcrun 于 2013-01-09 10:39:38 编辑 代码如下:
Option Explicit
Dim kk As Integer
Dim a(0 To 8) As Integer
Private Sub Command1_Click()
Dim I As Integer
Randomize
Dim k As Integer
Dim j As Integer
a(0) = Int(Rnd * 8)
For I = 1 To 7
Do
k = Int(Rnd * 8)
For j = 0 To I - 1
If k = a(j) Then
Exit For
End If
Next j
While j < I
a(I) = k
Next I
a(8) = -1
For I = 0 To 7
P(I).Picture = Pc.GraphicCell(a(I))
Next I
kk = 8
End Sub
Private Sub P_Click(Index As Integer)
Dim T As Integer
Dim b As Boolean
b = True
If (Abs(Index - kk) = 1 And _(Index \ 3 = kk \ 3)) Or _(Abs(kk - Index) = 3) Then
P(kk).Picture = P(Index).Picture
P(Index).Picture = LoadPicture
T = a(kk): a(kk) = a(Index): a(Index) = T
kk = Index
End If
For T = 0 To 7
If a(T) <> T Then
MsgBox "ok"
b = False
Exit For
End If
Next T
If b = True Then MsgBox "拼好了"
End Sub