C#漢諾塔演示和代碼_第1頁
C#漢諾塔演示和代碼_第2頁
已閱讀5頁,還剩7頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、 12/12C#漢諾塔演示和代碼 漢諾塔的演示界面: 本系統(tǒng)顯示的是漢諾塔的演示效果,分別有播放,暫停,和停止,右邊顯示的是每一步的動(dòng)作,同時(shí)記錄操作次數(shù),可以調(diào)節(jié)演示的速度。 漢諾塔界面代碼: namespace honio4 partial class Form1 / / 清理所有正在使用的資源。 / / 如果應(yīng)釋放托管資源,為true;否則為false。 protected override void Dispose(bool disposing) if (disposing & (components != null) components.Dispose(); base.Dispos

2、e(disposing); #region Windows 窗體設(shè)計(jì)器生成的代碼 / / 設(shè)計(jì)器支持所需的方法- 不要 / 使用代碼編輯器修改此方法的內(nèi)容。 / private void InitializeComponent() http:/./doc/6cfc0d22ccbff121dd368364.html ponents = new http:/./doc/6cfc0d22ccbff121dd368364.html ponentModel.Container(); this.panel1 = new System.Windows.Forms.Panel(); this.panel2 =

3、 new System.Windows.Forms.Panel(); this.panel3 = new System.Windows.Forms.Panel(); http:/./doc/6cfc0d22ccbff121dd368364.html bel1 = new http:/./doc/6cfc0d22ccbff121dd368364.html bel(); this.udLevels = new System.Windows.Forms.NumericUpDown(); this.btnStart = new System.Windows.Forms.Button(); this.b

4、tnPause = new System.Windows.Forms.Button(); this.btnStop = new System.Windows.Forms.Button(); http:/./doc/6cfc0d22ccbff121dd368364.html bel2 = new http:/./doc/6cfc0d22ccbff121dd368364.html bel(); this.trackSpeed = new System.Windows.Forms.TrackBar(); http:/./doc/6cfc0d22ccbff121dd368364.html bel3 =

5、 new http:/./doc/6cfc0d22ccbff121dd368364.html bel(); gress = new System.Windows.Forms.ProgressBar(); this.tmrPlay = new System.Windows.Forms.Timer(http:/./doc/6cfc0d22ccbff121dd368364.html ponents); this.listBox1 = new System.Windows.Forms.ListBox(); http:/./doc/6cfc0d22ccbff121dd368364.html bel4 =

6、 new http:/./doc/6cfc0d22ccbff121dd368364.html bel(); http:/./doc/6cfc0d22ccbff121dd368364.html bel5 = new http:/./doc/6cfc0d22ccbff121dd368364.html bel(); http:/./doc/6cfc0d22ccbff121dd368364.html bel6 = new http:/./doc/6cfc0d22ccbff121dd368364.html bel(); http:/./doc/6cfc0d22ccbff121dd368364.html

7、bel7 = new http:/./doc/6cfc0d22ccbff121dd368364.html bel(); http:/./doc/6cfc0d22ccbff121dd368364.html bel8 = new http:/./doc/6cfc0d22ccbff121dd368364.html bel(); (http:/./doc/6cfc0d22ccbff121dd368364.html ponentModel.ISupportInitialize)(this.udLevels).BeginInit(); (http:/./doc/6cfc0d22ccbff121dd3683

8、64.html ponentModel.ISupportInitialize)(this.trackSpeed).BeginInit(); this.SuspendLayout(); / / panel1 / this.panel1.Location = new System.Drawing.Point(16, 16); http:/./doc/6cfc0d22ccbff121dd368364.html = panel1; this.panel1.Size = new System.Drawing.Size(96, 144); this.panel1.TabIndex = 7; this.pa

9、nel1.Paint += new System.Windows.Forms.PaintEventHandler(this.panel1_Paint); / / panel2 / this.panel2.Location = new System.Drawing.Point(136, 16); http:/./doc/6cfc0d22ccbff121dd368364.html = panel2; this.panel2.Size = new System.Drawing.Size(96, 144); this.panel2.TabIndex = 8; this.panel2.Paint +=

10、new System.Windows.Forms.PaintEventHandler(this.panel2_Paint); / / panel3 / this.panel3.Location = new System.Drawing.Point(256, 16); http:/./doc/6cfc0d22ccbff121dd368364.html = panel3; this.panel3.Size = new System.Drawing.Size(96, 144); this.panel3.TabIndex = 8; this.panel3.Paint += new System.Win

11、dows.Forms.PaintEventHandler(this.panel3_Paint); / / label1 / http:/./doc/6cfc0d22ccbff121dd368364.html bel1.Location = new System.Drawing.Point(16, 168); http:/./doc/6cfc0d22ccbff121dd368364.html = label1; http:/./doc/6cfc0d22ccbff121dd368364.html bel1.Size = new System.Drawing.Size(42, 21); http:/

12、./doc/6cfc0d22ccbff121dd368364.html bel1.TabIndex = 1; http:/./doc/6cfc0d22ccbff121dd368364.html bel1.Text = 層數(shù):; http:/./doc/6cfc0d22ccbff121dd368364.html bel1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; / / udLevels / this.udLevels.Location = new System.Drawing.Point(51, 166); this.udL

13、evels.Maximum = new decimal(new int 5, 0, 0, 0); this.udLevels.Minimum = new decimal(new int 1, 0, 0, 0); http:/./doc/6cfc0d22ccbff121dd368364.html = udLevels; this.udLevels.Size = new System.Drawing.Size(32, 21); this.udLevels.TabIndex = 9; this.udLevels.TextAlign = System.Windows.Forms.HorizontalA

14、lignment.Center; this.udLevels.Value = new decimal(new int 3, 0, 0, 0); / / btnStart / this.btnStart.Location = new System.Drawing.Point(89, 164); http:/./doc/6cfc0d22ccbff121dd368364.html = btnStart; this.btnStart.Size = new System.Drawing.Size(48, 23); this.btnStart.TabIndex = 10; this.btnStart.Te

15、xt = 播放; this.btnStart.Click += new System.EventHandler(this.btnStart_Click_1); / / btnPause / this.btnPause.Enabled = false; this.btnPause.Location = new System.Drawing.Point(143, 163); http:/./doc/6cfc0d22ccbff121dd368364.html = btnPause; this.btnPause.Size = new System.Drawing.Size(48, 23); this.

16、btnPause.TabIndex = 11; this.btnPause.Text = 暫停; this.btnPause.Click += new System.EventHandler(this.btnPause_Click_1); / / btnStop / this.btnStop.Enabled = false; this.btnStop.Location = new System.Drawing.Point(197, 164); http:/./doc/6cfc0d22ccbff121dd368364.html = btnStop; this.btnStop.Size = new

17、 System.Drawing.Size(48, 23); this.btnStop.TabIndex = 12; this.btnStop.Text = 停止; this.btnStop.Click += new System.EventHandler(this.btnStop_Click_1); / / label2 / http:/./doc/6cfc0d22ccbff121dd368364.html bel2.Location = new System.Drawing.Point(251, 163); http:/./doc/6cfc0d22ccbff121dd368364.html

18、= label2; http:/./doc/6cfc0d22ccbff121dd368364.html bel2.Size = new System.Drawing.Size(32, 23); http:/./doc/6cfc0d22ccbff121dd368364.html bel2.TabIndex = 13; http:/./doc/6cfc0d22ccbff121dd368364.html bel2.Text = 慢速; http:/./doc/6cfc0d22ccbff121dd368364.html bel2.TextAlign = System.Drawing.ContentAl

19、ignment.MiddleLeft; / / trackSpeed / this.trackSpeed.Location = new System.Drawing.Point(278, 163); this.trackSpeed.Minimum = 1; http:/./doc/6cfc0d22ccbff121dd368364.html = trackSpeed; this.trackSpeed.Size = new System.Drawing.Size(56, 45); this.trackSpeed.TabIndex = 14; this.trackSpeed.TickStyle =

20、System.Windows.Forms.TickStyle.None; this.trackSpeed.Value = 1; this.trackSpeed.Scroll += new System.EventHandler(this.trackSpeed_Scroll_1); / / label3 / http:/./doc/6cfc0d22ccbff121dd368364.html bel3.Location = new System.Drawing.Point(329, 168); http:/./doc/6cfc0d22ccbff121dd368364.html = label3;

21、http:/./doc/6cfc0d22ccbff121dd368364.html bel3.Size = new System.Drawing.Size(32, 23); http:/./doc/6cfc0d22ccbff121dd368364.html bel3.TabIndex = 15; http:/./doc/6cfc0d22ccbff121dd368364.html bel3.Text = 快速; http:/./doc/6cfc0d22ccbff121dd368364.html bel3.TextAlign = System.Drawing.ContentAlignment.Mi

22、ddleRight; / / progress / gress.Location = new System.Drawing.Point(25, 200); http:/./doc/6cfc0d22ccbff121dd368364.html = progress; gress.Size = new System.Drawing.Size(336, 8); gress.TabIndex = 16; / / tmrPlay / this.tmrPlay.Interval = 1000; this.tmrPlay.Tick += new System.EventHandler(this.tmrPlay

23、_Tick_1); / / listBox1 / this.listBox1.FormattingEnabled = true; this.listBox1.ItemHeight = 12; this.listBox1.Location = new System.Drawing.Point(379, -1); http:/./doc/6cfc0d22ccbff121dd368364.html = listBox1; this.listBox1.Size = new System.Drawing.Size(219, 256); this.listBox1.TabIndex = 17; / / l

24、abel4 http:/./doc/6cfc0d22ccbff121dd368364.html bel4.AutoSize = true; http:/./doc/6cfc0d22ccbff121dd368364.html bel4.Location = new System.Drawing.Point(56, 1); http:/./doc/6cfc0d22ccbff121dd368364.html = label4; http:/./doc/6cfc0d22ccbff121dd368364.html bel4.Size = new System.Drawing.Size(17, 12);

25、http:/./doc/6cfc0d22ccbff121dd368364.html bel4.TabIndex = 18; http:/./doc/6cfc0d22ccbff121dd368364.html bel4.Text = 甲; / / label5 / http:/./doc/6cfc0d22ccbff121dd368364.html bel5.AutoSize = true; http:/./doc/6cfc0d22ccbff121dd368364.html bel5.Location = new System.Drawing.Point(182, 1); http:/./doc/

26、6cfc0d22ccbff121dd368364.html = label5; http:/./doc/6cfc0d22ccbff121dd368364.html bel5.Size = new System.Drawing.Size(17, 12); http:/./doc/6cfc0d22ccbff121dd368364.html bel5.TabIndex = 19; http:/./doc/6cfc0d22ccbff121dd368364.html bel5.Text = 乙; / / label6 / http:/./doc/6cfc0d22ccbff121dd368364.html

27、 bel6.AutoSize = true; http:/./doc/6cfc0d22ccbff121dd368364.html bel6.Location = new System.Drawing.Point(299, 1); http:/./doc/6cfc0d22ccbff121dd368364.html = label6; http:/./doc/6cfc0d22ccbff121dd368364.html bel6.Size = new System.Drawing.Size(17, 12); http:/./doc/6cfc0d22ccbff121dd368364.html bel6

28、.TabIndex = 20; http:/./doc/6cfc0d22ccbff121dd368364.html bel6.Text = 丙; / / label7 / http:/./doc/6cfc0d22ccbff121dd368364.html bel7.AutoSize = true; http:/./doc/6cfc0d22ccbff121dd368364.html bel7.Location = new System.Drawing.Point(242, 232); http:/./doc/6cfc0d22ccbff121dd368364.html = label7; http

29、:/./doc/6cfc0d22ccbff121dd368364.html bel7.Size = new System.Drawing.Size(65, 12); http:/./doc/6cfc0d22ccbff121dd368364.html bel7.TabIndex = 21; http:/./doc/6cfc0d22ccbff121dd368364.html bel7.Text = 操作次數(shù):; / / label8 / http:/./doc/6cfc0d22ccbff121dd368364.html bel8.AutoSize = true; http:/./doc/6cfc0

30、d22ccbff121dd368364.html bel8.Location = new System.Drawing.Point(315, 232); http:/./doc/6cfc0d22ccbff121dd368364.html = label8; http:/./doc/6cfc0d22ccbff121dd368364.html bel8.Size = new System.Drawing.Size(17, 12); http:/./doc/6cfc0d22ccbff121dd368364.html bel8.TabIndex = 22; http:/./doc/6cfc0d22cc

31、bff121dd368364.html bel8.Text = ; http:/./doc/6cfc0d22ccbff121dd368364.html bel8.Click += new System.EventHandler(http:/./doc/6cfc0d22ccbff121dd368364.html bel8_Click); / Form1 / this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Fon

32、t; this.ClientSize = new System.Drawing.Size(601, 262); this.Controls.Add(http:/./doc/6cfc0d22ccbff121dd368364.html bel8); this.Controls.Add(http:/./doc/6cfc0d22ccbff121dd368364.html bel7); this.Controls.Add(http:/./doc/6cfc0d22ccbff121dd368364.html bel6); this.Controls.Add(http:/./doc/6cfc0d22ccbff

33、121dd368364.html bel5); this.Controls.Add(http:/./doc/6cfc0d22ccbff121dd368364.html bel4); this.Controls.Add(this.listBox1); this.Controls.Add(gress); this.Controls.Add(http:/./doc/6cfc0d22ccbff121dd368364.html bel3); this.Controls.Add(this.trackSpeed); this.Controls.Add(http:/./doc/6cfc0d22ccbff121

34、dd368364.html bel2); this.Controls.Add(this.btnStop); this.Controls.Add(this.btnPause); this.Controls.Add(this.btnStart); this.Controls.Add(this.udLevels); this.Controls.Add(http:/./doc/6cfc0d22ccbff121dd368364.html bel1); this.Controls.Add(this.panel3); this.Controls.Add(this.panel2); this.Controls

35、.Add(this.panel1); http:/./doc/6cfc0d22ccbff121dd368364.html = Form1; this.Text = hanoi tower; (http:/./doc/6cfc0d22ccbff121dd368364.html ponentModel.ISupportInitialize)(this.udLevels).EndInit(); (http:/./doc/6cfc0d22ccbff121dd368364.html ponentModel.ISupportInitialize)(this.trackSpeed).EndInit(); t

36、his.ResumeLayout(false); this.PerformLayout(); #endregion privateSystem.Windows.Forms.Panel panel1; privateSystem.Windows.Forms.Panel panel2; privateSystem.Windows.Forms.Panel panel3; http:/./doc/6cfc0d22ccbff121dd368364.html bel label1; privateSystem.Windows.Forms.NumericUpDownudLevels; privateSyst

37、em.Windows.Forms.ButtonbtnStart; privateSystem.Windows.Forms.ButtonbtnPause; privateSystem.Windows.Forms.ButtonbtnStop; http:/./doc/6cfc0d22ccbff121dd368364.html bel label2; privateSystem.Windows.Forms.TrackBartrackSpeed; http:/./doc/6cfc0d22ccbff121dd368364.html bel label3; privateSystem.Windows.Fo

38、rms.ProgressBar progress; privateSystem.Windows.Forms.TimertmrPlay; privateSystem.Windows.Forms.ListBox listBox1; http:/./doc/6cfc0d22ccbff121dd368364.html bel label4; http:/./doc/6cfc0d22ccbff121dd368364.html bel label5; http:/./doc/6cfc0d22ccbff121dd368364.html bel label6; http:/./doc/6cfc0d22ccbf

39、f121dd368364.html bel label7; http:/./doc/6cfc0d22ccbff121dd368364.html bel label8; C#程序代碼: using System; usingSystem.Collections.Generic; http:/./doc/6cfc0d22ccbff121dd368364.html ponentModel; usingSystem.Data; usingSystem.Drawing; usingSystem.Linq; usingSystem.Text; usingSystem.Windows.Forms; usin

40、g System.IO; using System.Drawing.Drawing2D; namespace honio4 public partial class Form1 : Form public Form1() InitializeComponent(); privateMemoryStreamms; privateint levels; int index = 0; int index1 = 0; int index2= 0; int goon = 1; int index9 = 0; private void WriteInstructions(intsrc, intheight

41、,inthelp,intdest) if (height 乙); index9+; label8.Text = index9.ToString(); if (dest = 2) Push(stacksss, lbl); lbl.Parent = panelsdest; lbl.Top = (9 - index2) * 16; listBox1.Items.Add(甲丙); index9+; label8.Text = index9.ToString(); else if (src = 1) Label lbl = (Label)Pop(stackss); if (dest = 0) Push(

42、stacks, lbl); lbl.Parent = panelsdest; lbl.Top = (9 - index) * 16; listBox1.Items.Add(乙甲); index9+; label8.Text = index9.ToString(); if (dest = 1) Push(stackss, lbl); lbl.Parent = panelsdest; lbl.Top = (9 - index1 ) * 16; if (dest = 2) Push(stacksss, lbl); lbl.Parent = panelsdest; lbl.Top = (9 - ind

43、ex2) * 16; listBox1.Items.Add(乙丙); index9+; label8.Text = index9.ToString(); else Label lbl = (Label)Pop(stacksss); if (dest = 0) Push(stacks, lbl); lbl.Parent = panelsdest; lbl.Top = (9 - index) * 16; listBox1.Items.Add(丙甲); index9+; label8.Text = index9.ToString(); if (dest = 1) Push(stackss, lbl); lbl.Parent = panelsdest; lbl.Top = (9 - index1) * 16; listBox1.Items.Add(丙乙); index9+; label8.Text =

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論