C#汉诺塔,俄罗斯方块,扫雷游戏代码

  • 格式:txt
  • 大小:23.42 KB
  • 文档页数:9
Plate[i].Left = 48 + (n - i) * 5;
Plate[i].Top = 167 - (n - i + 1) * PlateHeight;
Plate[i].Width = 100 - (n - i) * 10;
{
//处理盘子MouseDown的公共事件
PictureBox p1;
p1 = (PictureBox)sender;//将被点击的PictureBox赋给定义的p1变量
int sText;
Plate[i].SizeMode = PictureBoxSizeMode.StretchImage;
Plate[i].Parent = pictureBox1;
Plate[i].MouseMove += new MouseEventHandler(plate_MouseMove);
}
}
if (C.Contains(sText))
{
foreach (int i in C)
{
if (i < sText)
//ArrayList 就是数组列表,它位于System.Collections名称空间下,是集合类型。
private int oldx, oldy;
private void load_plate(sText);
Plate[sText].Left = oldx + 170;
}
if (C.Contains(sText))
{
//处理盘子移动的公共事件
PictureBox p1;
p1 =(PictureBox )sender; //将被点击的PictureBox赋给定义的p1变量
if (isDragging)
isDragging = false;
int sText;
PictureBox p1;
bool cango = false;
p1 = (PictureBox)sender; //将被点击的PictureBox赋给定义的p1变量
Plate[i].MouseUp += plate_MouseUp;
Plate[i].MouseDown += plate_MouseDown;
}
for (i = n; i >= 1; i += -1)
{
if (i < sText)
{
MessageBox.Show("请选择最上面的盘子");
return;
}
private int i; //移动的次数
public PictureBox[] Plate = new PictureBox[11];
const int PlateHeight = 17; //盘片厚度
private bool isDragging = false;
Plate[i].Height = PlateHeight;
Plate[i].Tag = i; //设置盘片编号
Plate[i].Image = new Bitmap("Plate.bmp"); //盘子图片
//最上方的盘片
System.Windows.Forms.Cursor.Current = Cursors.Hand;
if (e.Button == System.Windows.Forms.MouseButtons.Left)
汉诺塔游戏代码
using System;
using System.Collections.Generic;
using ponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
private void plate_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
//处理盘子MouseUp的公共事件
if (!isDragging) return;
{
x1 = e.X; y1 = e.Y;
oldx = p1.Left; oldy = p1.Top;
isDragging = true;
}
}
Plate[sText].Top = 150 - (B.Count - 1) * Plate[sText].Height;
if (A.Contains(sText))
{ //从A柱到B柱
private int x1, y1;
private ArrayList A = new ArrayList();
private ArrayList B = new ArrayList();
private ArrayList C = new ArrayList();
{
if (B.Count == 0 || sText < (int)B[B.Count - 1])
{
//小于已有盘片
B.Add(sText);
if (i < sText)
{
MessageBox.Show("请选择最上面的盘子");
return;
}
{ //从C柱到B柱
C.Remove(sText);
Plate[sText].Left = oldx - 170;
}
//盘片编号从上往下1,2,...n
for (i = 1; i <= n; i++)
{
Plate[i] = new PictureBox();
this.Controls.Add(Plate[i]);
using System.Collections;
namespace 汉诺塔递归
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
sText = Convert.ToInt16(p1.Tag); //获取盘片编号
//盘片移到B柱
if ((p1.Left + p1.Width / 2) >= 150 + 80 & (p1.Left + p1.Width / 2) < 320 + 80)
{
MessageBox.Show("请选择最上面的盘子");
return;
}
}
}
{
A.Add(i); //A数组列表添加条目
}
}
private void plate_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
sText = Convert.ToInt16(p1.Tag); //获取盘片编号
//首先判断是否不是最上面的盘子
if (A.Contains(sText))
{
foreach (int i in A)
{
p1.Left = p1.Left - x1 + e.X;
p1.Top = p1.Top - y1 + e.Y;
}
}
private void plate_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
}
}
}
if (B.Contains(sText))
{
foreach (int i in B)
{
cango = true;
}
}
//盘片移到C柱
if ((p1.Left + p1.Width / 2) >= 320 + 80 & (p1.Left + p1.Width / 2) < 490 + 80)

下载文档原格式

  / 9