| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 561 人关注过本帖
标题:关于汉诺塔的问题
只看楼主 加入收藏
copyyo
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2010-5-21
收藏
 问题点数:0 回复次数:3 
关于汉诺塔的问题
怎样修改程序使得能够控制汉诺塔移动快慢
我是新手啊,请大家帮帮我

Dim pan(10) As Shape
Dim l(3) As Integer
Dim p(3) As Integer
Dim k As Integer
Dim h(3, 10) As Integer
Dim num As Integer

Private Sub Command1_Click()
For i = 1 To num
h(1, i) = i
Next
p(1) = num
k = 0
Call han(num, 1, 2, 3)
s = l(1): l(1) = l(3): l(3) = s
For i = 1 To 3
p(i) = 0
Next

End Sub

Private Sub Form_Activate()
num = Val(Text1.Text)
For i = 1 To num
  pan(i).Left = pan(i).Tag
  pan(i).Visible = True
Next
For i = num + 1 To 10
  pan(i).Visible = False
Next
For i = 1 To 3
 l(i) = Line1(i - 1).X1
Next


End Sub

Private Sub Form_Load()
For i = 1 To 10
 Set pan(i) = Shape1(i - 1)
 pan(i).Tag = pan(i).Left
Next

End Sub

Private Sub han(m As Integer, u As Integer, v As Integer, w As Integer)
If m = 1 Then
Call yidong(u, w)
Else
Call han(m - 1, u, w, v)
Call yidong(u, w)
Call han(m - 1, v, u, w)
End If

End Sub
Private Sub yidong(X As Integer, Y As Integer)
a = p(X)
b = p(Y) + 1
h(Y, b) = h(X, a)
pan(h(Y, b)).Top = 200
Call yianshi(0.1)
pan(h(Y, b)).Left = l(Y) - pan(h(Y, b)).Width / 2
Call yianshi(0.2)
pan(h(Y, b)).Top = 1700 - p(Y) * 100
Call yianshi(0.1)
p(X) = a - 1
p(Y) = b
k = k + 1
Label3.Caption = "移动了" + LTrim(Str(k)) + "次"
Form1.Refresh

End Sub

Private Sub yianshi(pausetime)
Dim start
start = Timer
Do While Timer < start + pausetime
Loop


End Sub

Private Sub Text1_Change()
n = Val(Text1.Text)
 If n > 2 And n < 10 Then
  Form_Activate
End If

End Sub
搜索更多相关主题的帖子: 汉诺塔 
2010-05-21 22:29
copyyo
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2010-5-21
收藏
得分:0 
还能够将移动过程写入txt文件。。。。。
2010-05-21 22:31
pariszh
该用户已被删除
收藏
得分:0 
提示: 作者被禁止或删除 内容自动屏蔽
2010-06-11 23:02
jiashie
Rank: 8Rank: 8
等 级:贵宾
威 望:10
帖 子:237
专家分:999
注 册:2009-4-30
收藏
得分:0 
这代码是LZ写的么?
控制时间:在调用yianshi()时给的参数小一点就行了。比如yianshi(0.05)
在yidong()的过程中记录下移动的过程,(但是不要在这个函数中用open写文件,把移动过程保存到一个字符串中就行了,效率问题。要等到完成时一次性写入文件,)
2010-06-12 10:29
快速回复:关于汉诺塔的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.027005 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved