- 1、本文档共8页,可阅读全部内容。
- 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
所需图片:
设计游戏窗体(form1.cs)
创建新Windows应用程序项目,在新窗体上添加1个图片框picturebox1(显示ABC三个柱子背景)、1个文本框textbox1(用来设置盘子的数量)、1个标签label(text设置为盘子数)
添加两个按钮(button) text属性为“开始游戏”和自动演化
实现代码
//代码测试都可以使用 不懂联系邮箱:1278263100@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;
namespace 汉诺塔递归
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private int i; //移动的次数
public PictureBox[] Plate = new PictureBox[11];
const int PlateHeight = 17; //盘片厚度
private bool isDragging = false;
private int x1, y1;
private ArrayList A = new ArrayList();
private ArrayList B = new ArrayList();
private ArrayList C = new ArrayList();
//ArrayList 就是数组列表,它位于System.Collections名称空间下,是集合类型。
private int oldx, oldy;
private void load_plate(int n)
{
//加载盘片
//盘片编号从上往下1,2,...n
for (i = 1; i = n; i++)
{
Plate[i] = new PictureBox();
this.Controls.Add(Plate[i]);
Plate[i].Left = 48 + (n - i) * 5;
Plate[i].Top = 167 - (n - i + 1) * PlateHeight;
Plate[i].Width = 100 - (n - i) * 10;
Plate[i].Height = PlateHeight;
Plate[i].Tag = i; //设置盘片编号
Plate[i].Image = new Bitmap(Plate.bmp); //盘子图片
Plate[i].SizeMode = PictureBoxSizeMode.StretchImage;
Plate[i].Parent = pictureBox1;
Plate[i].MouseMove += new MouseEventHandler(plate_MouseMove);
Plate[i].MouseUp += plate_MouseUp;
Plate[i].MouseDown += plate_MouseDown;
}
for (i = n; i = 1; i += -1)
{
A.Add(i); //A数组列表添加条目
}
}
pr
文档评论(0)