用VB编写的简单汉诺塔程序
Private Sub cmdStart_Click()
n = Int(Text1.Text)
ReDim Data(1 To n, 1 To 3)
For i = 1 To n
For j = 1 To 3
Data(i, j) = 0
Next j
Next i
For i = 1 To n
Data(i, 1) = i
Next i
ColNow = 1
SelNum = 0
Call ShowPic
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyUp
If SelNum = 0 Then SelNum = Data(1, ColNow): Call Pop
Case vbKeyDown
If SelNum <> 0 Then
If Push = True Then SelNum = 0
If Data(n, 3) = n Then Call ShowPic: MsgBox "恭喜你通过!", vbOKOnly, "Pass"
End If
Case vbKeyLeft
ColNow = ColNow - 1
If ColNow < 1 Then ColNow = 1
Case vbKeyRight
ColNow = ColNow + 1
If ColNow > 3 Then ColNow = 3
End Select
Call ShowPic
End Sub
2022-09-28 12:44:11
11KB
vb
汉诺塔
1