代码如下:
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
我想做一个vb的拼图游戏,但看不懂上面的代码,求大神大致解释一下这些代码,最好是每一行代码干什么的帮忙填充上注释,小弟跪求。在此先谢过。
vb 游戏 拼图 代码
------解决方案--------------------------------------------------------
这是哪位兄台写的代码,连1/10的注释都没有啊。
你这个还需要界面控件配合的,Command1好理解,P1那个貌似是PictureBox数组。唉,你应该有源码吧