• 大小: 49KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-05-29
  • 语言: C#
  • 标签: c#  汉诺塔  hannoi  动态  

资源简介

C#可视化动态汉诺塔实现,盘子移动!vs2010,低版本,新建项目然后把改窗体添加进去即可!

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.Regularexpressions;

namespace han
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        Graphics g;//获得graphic
        //3个柱子和一个底板
        Pillar pillar;
        Pillar pillarA;
        Pillar pillarB;
        Pillar pillarC;
        //当前disk个数 
        HanDisk[] disks;
        int disksNum;
        private void Form1_Load(object sender EventArgs e)
        {
            //初始化界面,柱子等
            pillar = new Pillar(““);
            pillarA = new Pillar(“A“);
            pillarB = new Pillar(“B“);
            pillarC = new Pillar(“C“);
            disksNum = 0;
            //hd = new HanDisk(this100100100100);             
        }

        private void Form1_MouseMove(object sender MouseEventArgs e)
        {
            this.textBox1.Text = e.X.ToString() + “ “ + e.Y.ToString();
        }
        //生成hannoi
        private void button1_Click(object sender EventArgs e)
        {
            if ((!IsInt(this.textBox2.Text.ToString()))||(this.textBox2.Text.ToString()==““))
            {
                MessageBox.Show(“请输入不为0的整数“);
                this.textBox2.Text = ““;
                return;
            }
            disksNum=Convert.ToInt32(this.textBox2.Text.ToString());
            if (disksNum == 0)
            {
                MessageBox.Show(“请输入不为0的整数!“);
                return;
            }
            this.textBox3.Text = ““;
            //去除之前的盘子
            if (disks != null)
            {
                if (disks.Length != 0)
                HanDisk.ClearDisks(disks);
                pillarA.ClearAll();
                pillarB.ClearAll();
                pillarC.ClearAll();

            }
            //批量生成盘子,并加到柱子A上
            disks=new HanDisk[disksNum+1];
            int len=160;//盘子长度
            int lenDece=150/disksNum;//盘子递减量
            int locy=370;
            for (int i = disksNum; i >0; i--)
            {
                //MessageBox.Show(locy.ToString());
                disks[i] =new HanDisk(thispillarA.locx-len/2locylen);
                disks[i].id =i;
                //加到pillaA中
                pillarA.disks.Add(disks[i]);
                len -= lenDece;
                locy-=10;
            }
            pillarA.high = disks[1].imageP.Location.Y;
        }
        //开始解析hannoi
        private void button2_Click(object sender EventArgs e)
        {
            //HanDisk.MoveDisk(hd 300 300);
            Hanoi(disksNumpillarApillarBpillarC);
        }
        //绘界面
        private void Form1_Paint(object sender PaintEventArgs e)
        {
            pillar.Paint(this0380100010Color.Gray0);
            pillarA.Paint(this

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2012-11-06 18:11  han\
     目录           0  2012-11-06 18:04  han\bin\
     目录           0  2012-11-06 22:37  han\bin\Debug\
     文件       13312  2012-11-07 12:27  han\bin\Debug\han.exe
     文件       30208  2012-11-07 12:27  han\bin\Debug\han.pdb
     文件       11600  2012-11-07 12:29  han\bin\Debug\han.vshost.exe
     文件         490  2010-03-17 22:39  han\bin\Debug\han.vshost.exe.manifest
     目录           0  2012-11-06 18:04  han\bin\Release\
     文件        7041  2012-11-07 12:27  han\Form1.cs
     文件        6895  2012-11-06 22:15  han\Form1.Designer.cs
     文件        5817  2012-11-06 22:15  han\Form1.resx
     文件        3665  2012-11-06 18:10  han\hannoi.csproj
     目录           0  2012-11-06 18:01  han\obj\
     目录           0  2012-11-06 18:01  han\obj\x86\
     目录           0  2012-11-07 12:27  han\obj\x86\Debug\
     文件        4440  2012-11-06 22:37  han\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache
     文件        6238  2012-11-07 12:27  han\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
     文件         272  2012-11-06 22:15  han\obj\x86\Debug\GenerateResource.read.1.tlog
     文件         626  2012-11-06 22:15  han\obj\x86\Debug\GenerateResource.write.1.tlog
     文件         727  2012-11-06 18:10  han\obj\x86\Debug\han.csproj.FileListAbsolute.txt
     文件       13312  2012-11-07 12:27  han\obj\x86\Debug\han.exe
     文件         180  2012-11-06 22:15  han\obj\x86\Debug\han.Form1.resources
     文件       30208  2012-11-07 12:27  han\obj\x86\Debug\han.pdb
     文件         180  2012-11-06 18:10  han\obj\x86\Debug\han.Properties.Resources.resources
     文件         727  2012-11-07 12:29  han\obj\x86\Debug\hannoi.csproj.FileListAbsolute.txt
     文件        7897  2012-11-07 12:27  han\obj\x86\Debug\ResolveAssemblyReference.cache
     目录           0  2012-11-06 18:01  han\obj\x86\Debug\TempPE\
     文件         484  2012-11-06 18:01  han\Program.cs
     目录           0  2012-11-06 18:01  han\Properties\
     文件        1362  2012-11-06 18:01  han\Properties\AssemblyInfo.cs
     文件        2854  2012-11-06 18:01  han\Properties\Resources.Designer.cs
............此处省略3个文件信息

评论

共有 条评论