Dim Index As String
Dim a As Integer
Private Sub Command1_Click(Index As Integer)
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Form_Load()
Randomize
a = Int(Rnd * 8) + 1
For n = 0 To 7
For a = 1 To 8
Static Index As Integer
Index = (Index + 1) Mod 8
Command1(Index).Caption = a
Next
Next
End Sub
此遊戲是九個command的陣列控制項,
我的問題是
能否把自已想要移動的command和沒數字的command做互換的動作
寫在
Private Sub Command1_Click(Index As Integer)
End Sub
裡然後移動完數字項後
123
456
78
能顯示msgbox"贏"
謝謝指導
Dim a As Integer
Private Sub Command1_Click(Index As Integer)
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Form_Load()
Randomize
a = Int(Rnd * 8) + 1
For n = 0 To 7
For a = 1 To 8
Static Index As Integer
Index = (Index + 1) Mod 8
Command1(Index).Caption = a
Next
Next
End Sub
此遊戲是九個command的陣列控制項,
我的問題是
能否把自已想要移動的command和沒數字的command做互換的動作
寫在
Private Sub Command1_Click(Index As Integer)
End Sub
裡然後移動完數字項後
123
456
78
能顯示msgbox"贏"
謝謝指導
文章標籤
全站熱搜

Dim a(1 To 8) As Integer Private Sub Form_Load() Randomize For Index = 0 To 7 n = Int(Rnd * 8) + 1 If a(n) Then Index = Index - 1 Else a(n) = n Command1(Index).Caption = n End If Next Command1(8).Caption = "" End Sub Private Sub Command1_Click(Index As Integer) If Index Mod 3 <> 0 Then If Command1(Index - 1).Caption = "" Then Call Swap(Index - 1, Index) If (Index + 1) Mod 3 <> 0 Then If Command1(Index + 1).Caption = "" Then Call Swap(Index + 1, Index) If Index > 2 Then If Command1(Index - 3).Caption = "" Then Call Swap(Index - 3, Index) If Index < 6 Then If Command1(Index + 3).Caption = "" Then Call Swap(Index + 3, Index) End Sub Private Sub Swap(n1, n2) Command1(n1).Caption = Command1(n2).Caption Command1(n2).Caption = "" End Sub msgbox"贏", 這部份自己想一想!
感謝"學到老"的指導 可是 Randomize For Index = 0 To 7 n = Int(Rnd * 8) + 1 If a(n) Then Index = Index - 1 Else a(n) = n Command1(Index).Caption = n End If Next Command1(8).Caption = "" 看不懂耶~~亂數n是由1到8如果....之後是怎麼解譯啊 還有 If Index Mod 3 <> 0 Then If Command1(Index - 1).Caption = "" Then Call Swap(Index - 1, Index) If (Index + 1) Mod 3 <> 0 Then If Command1(Index + 1).Caption = "" Then Call Swap(Index + 1, Index) If Index > 2 Then If Command1(Index - 3).Caption = "" Then Call Swap(Index - 3, Index) If Index < 6 Then If Command1(Index + 3).Caption = "" Then Call Swap(Index + 3, Index) 這個對我來說好像是亂碼一樣也是看不懂耶~好像是把index變成連續的數字嗎 然後再call Command1(n1).Caption = Command1(n2).Caption Command1(n2).Caption = "" 才能互換~~是嗎????????? 報欠了~問這麼多可是還是要謝謝你回文指導
Index: 陣列按鈕Command1索引數 For Index = 0 To 7 n = Int(Rnd * 8) + 1 '1~8之間任取一數,不是按順序 '利用陣列a(1 to 9)判斷是否產生重覆相同數,(先看a(n) = n)當a(n)<>0表示重覆 If a(n) Then 'a(n)是a(n)<>0的省略寫法,a(n)=0相當於False,a(n)<>0相當於True Index = Index - 1 '因為重覆所以退一個迴圈重取 Else a(n) = n '將該數置入陣列與該數相對順序位置 Command1(Index).Caption = n End If Next '以下為判斷鄰鈕是否是"",Index Mod 3 <> 0、(Index + 1) Mod 3 <> 0、Index > 2、Index < 6 利用索引數Index位置,判斷鄰鈕是否超過9格陣列外的位置