电脑桌面
添加小米粒文库到电脑桌面
安装后可以在桌面快捷访问

基于c#编写汉诺塔游戏讲解VIP专享VIP免费

基于c#编写汉诺塔游戏讲解_第1页
基于c#编写汉诺塔游戏讲解_第2页
基于c#编写汉诺塔游戏讲解_第3页
所需图片:设计游戏窗体(form1.cs)创建新 Windows 应用程序项目, 在新窗体上添加1 个图片框 picturebox1(显示 ABC 三个柱子背景)、1 个文本框 textbox1(用来设置盘子的数量)、1 个标签 label(text 设置为盘子数)添加两个按钮(button) text 属性为“开始游戏”和自动演化实现代码//代码测试都可以使用不懂联系邮箱:1278263100@qq.com 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 数组列表添加条目} } private void plate_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { //处理盘子移动的公共事件PictureBox p1; p1 =(P...

1、当您付费下载文档后,您只拥有了使用权限,并不意味着购买了版权,文档只能用于自身使用,不得用于其他商业用途(如 [转卖]进行直接盈利或[编辑后售卖]进行间接盈利)。
2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。
3、如文档内容存在违规,或者侵犯商业秘密、侵犯著作权等,请点击“违规举报”。

碎片内容

确认删除?
VIP
微信客服
  • 扫码咨询
会员Q群
  • 会员专属群点击这里加入QQ群
客服邮箱
回到顶部