⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 zhzform.cs

📁 这个源码是我从别的网站下载下来的!我是初学者,希望给我一点源码下载(文件包含连连看,俄罗斯方块,当代罗宾汉,智慧珠,贪吃蛇)
💻 CS
📖 第 1 页 / 共 4 页
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Drawing.Drawing2D;

namespace 自娱自乐
{
	/// <summary>
	/// ZHZForm 的摘要说明。
	/// </summary>
	public class ZHZForm : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Panel PanelBottom;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;
		private System.Windows.Forms.Button ButReStart;
		private System.Windows.Forms.Button ButExit;

		//声明全局变量
		private PictureBox[,] ZHU	 = new PictureBox[12,5];		
		private System.Drawing.Point mousePosition ;
		private int[]	ZHUDirection = new int[12] ;
		private int[,]	BottomPos	 = new int[55,2];

		public ZHZForm()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();

			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//
		}

		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(ZHZForm));
			this.PanelBottom = new System.Windows.Forms.Panel();
			this.ButReStart = new System.Windows.Forms.Button();
			this.ButExit = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// PanelBottom
			// 
			this.PanelBottom.AllowDrop = true;
			this.PanelBottom.BackColor = System.Drawing.Color.Transparent;
			this.PanelBottom.Name = "PanelBottom";
			this.PanelBottom.Size = new System.Drawing.Size(740, 400);
			this.PanelBottom.TabIndex = 0;
			// 
			// ButReStart
			// 
			this.ButReStart.BackColor = System.Drawing.Color.Transparent;
			this.ButReStart.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.ButReStart.ForeColor = System.Drawing.Color.Lime;
			this.ButReStart.Location = new System.Drawing.Point(10, 420);
			this.ButReStart.Name = "ButReStart";
			this.ButReStart.Size = new System.Drawing.Size(70, 25);
			this.ButReStart.TabIndex = 1;
			this.ButReStart.Text = "重 摆";
			this.ButReStart.Click += new System.EventHandler(this.ButReStart_Click);
			// 
			// ButExit
			// 
			this.ButExit.BackColor = System.Drawing.Color.Transparent;
			this.ButExit.DialogResult = System.Windows.Forms.DialogResult.Cancel;
			this.ButExit.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.ButExit.ForeColor = System.Drawing.Color.Lime;
			this.ButExit.Location = new System.Drawing.Point(100, 420);
			this.ButExit.Name = "ButExit";
			this.ButExit.Size = new System.Drawing.Size(70, 25);
			this.ButExit.TabIndex = 2;
			this.ButExit.Text = "退 出";
			this.ButExit.Click += new System.EventHandler(this.ButExit_Click);
			// 
			// ZHZForm
			// 
			this.AcceptButton = this.ButReStart;
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.BackColor = System.Drawing.Color.Black;
			this.CancelButton = this.ButExit;
			this.ClientSize = new System.Drawing.Size(742, 473);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.ButExit,
																		  this.ButReStart,
																		  this.PanelBottom});
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.MaximizeBox = false;
			this.MaximumSize = new System.Drawing.Size(750, 500);
			this.MinimumSize = new System.Drawing.Size(750, 500);
			this.Name = "ZHZForm";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "智慧珠";
			this.Load += new System.EventHandler(this.ZHZForm_Load);
			this.ResumeLayout(false);

		}
		#endregion

		private void ZHZForm_Load(object sender, System.EventArgs e)
		{
			//程序初始化
			//生成底图
			CreateZHU();
			ZHUPlace();
			CreateBottom();			
		}
		private void ButReStart_Click(object sender, System.EventArgs e)
		{
			//重摆
			ZHUPlace();
			ZHUPlace();
		}

		private void ButExit_Click(object sender, System.EventArgs e)
		{
			//退出
			this.Close();
		}		
		private void CreateBottom()
		{
			//生成空格子
			int i,j,center,left,top,count;
			center = (PanelBottom.Width/2)-10 ;
			top	 = PanelBottom.Height - 200 ;
			count = 0;
			for(i=0;i<10;i++)
			{
				left =  center - i*20;
				for(j=0;j<=i;j++)
				{
					Panel MyBottom		= new Panel() ;			
					MyBottom.Name		= "Bottom_"+i.ToString()+"_"+j.ToString() ;
					MyBottom.Parent		= PanelBottom;
					MyBottom.BackColor	= System.Drawing.Color.Gray ;
					MyBottom.Width		= 20 ;
					MyBottom.Height		= 20 ;
					MyBottom.Left		= left;
					MyBottom.Top		= top;	
					MyBottom.AllowDrop	= true ;						
					MyBottom.Visible	= true ;
					MyBottom.Enabled    = true ;
					MyBottom.Paint	   += new System.Windows.Forms.PaintEventHandler(this.Bottom_Paint);
					BottomPos[count,0]	= left ;
					BottomPos[count,1]	= top  ;
					left				= left + 40 ;
					count++;
				}
				top = top + 20 ;
			}					
		}
		private void CreateZHU()
		{
			//创建12个珠体
			int i,j,ZhuNum;
			for(i=0;i<12;i++)
			{
				ZhuNum = 3 ;
				if(i>0)	{	ZhuNum++ ; }
				if(i>3)	{	ZhuNum++ ; }
				for(j=0;j<ZhuNum;j++)
				{
					//用ZhuNum个珠对象生成一个珠体
					PictureBox MyPic	= new PictureBox() ;
					MyPic.Name			= "ZHU_"+i.ToString()+"_"+j.ToString();
					MyPic.Parent		= PanelBottom ;
					MyPic.SizeMode		= PictureBoxSizeMode.StretchImage ;
					MyPic.ClientSize	= new Size(20, 20);
					ZHUCOLOR(MyPic,i);					
					MyPic.Paint		   += new System.Windows.Forms.PaintEventHandler(this.ZHU_Paint);
					if(j == 0)
					{
						MyPic.MouseDown    += new System.Windows.Forms.MouseEventHandler(this.ZHU_MouseDown);
						MyPic.MouseMove    += new System.Windows.Forms.MouseEventHandler(this.ZHU_MouseMove);
						MyPic.MouseUp      += new System.Windows.Forms.MouseEventHandler(this.ZHU_MouseUp);
						MyPic.Move		   += new System.EventHandler(this.ZHU_Move);
					}					
					MyPic.Visible		= false;
					MyPic.Left			= 0;
					MyPic.Top			= 0;
					ZHU[i,j]			= MyPic ;
				}
			}
		}
		private void Bottom_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
		{
			//将Bottom对象外观改为圆形
			Panel MyBottom	= (Panel)sender ;	
			GraphicsPath gp = new GraphicsPath();
  		gp.AddEllipse(0, 0, 20, 20);
  		Region r = new Region(gp);
  		MyBottom.Region  = r;	
		}
		private void ZHU_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
		{
			//将ZHU对象外观改为圆形
			GraphicsPath gp = new GraphicsPath();
  		gp.AddEllipse(0, 0, 20, 20);
  		Region r = new Region(gp);
			PictureBox TmpSender = (PictureBox)sender ;
  		TmpSender.Region  = r;	
		}
		private void ZHUCOLOR(PictureBox ZhuPic,int type)
		{
			//设定珠体颜色
			switch (type)
			{
				case 0:
					ZhuPic.BackColor		= System.Drawing.Color.MediumAquamarine;
					break;
				case 1:
					ZhuPic.BackColor		= System.Drawing.Color.PaleVioletRed ;
					break;
				case 2:
					ZhuPic.BackColor		= System.Drawing.Color.Lime ;
					break;
				case 3:
					ZhuPic.BackColor		= System.Drawing.Color.Blue ;
					break;
				case 4:
					ZhuPic.BackColor		= System.Drawing.Color.Red ;
					break;
				case 5:
					ZhuPic.BackColor		= System.Drawing.Color.Green ;
					break;
				case 6:
					ZhuPic.BackColor		= System.Drawing.Color.Tomato ;
					break;
				case 7:
					ZhuPic.BackColor		= System.Drawing.Color.LightCoral ;
					break;
				case 8:
					ZhuPic.BackColor		= System.Drawing.Color.Violet ;
					break;
				case 9:
					ZhuPic.BackColor		= System.Drawing.Color.Yellow ;
					break;
				case 10:
					ZhuPic.BackColor		= System.Drawing.Color.Sienna ;
					break;
				case 11:
					ZhuPic.BackColor		= System.Drawing.Color.SandyBrown ;
					break;
			}					
		}
		private void ZHUPlace()
		{
			//对珠体位置初始化
			int i,j,ZhuNum;
			ZHU[0,0].Left = 30 ;
			ZHU[0,0].Top  = 10 ;			
			ZHUStatus0(1);
			ZHU[1,0].Left = 130 ;
			ZHU[1,0].Top  = 10 ;
			ZHUStatus1(1);
			ZHU[2,0].Left = 250 ;
			ZHU[2,0].Top  = 10 ;
			ZHUStatus2(1);
			ZHU[3,0].Left = 380 ;
			ZHU[3,0].Top  = 10 ;
			ZHUStatus3(1);
			ZHU[4,0].Left = 500 ;
			ZHU[4,0].Top  = 10 ;
			ZHUStatus4(1);
			ZHU[5,0].Left = 620 ;
			ZHU[5,0].Top  = 10 ;
			ZHUStatus5(1);
			ZHU[6,0].Left = 30 ;
			ZHU[6,0].Top  = 110 ;
			ZHUStatus6(1);
			ZHU[7,0].Left = 130 ;
			ZHU[7,0].Top  = 110 ;
			ZHUStatus7(1);
			ZHU[8,0].Left = 250 ;
			ZHU[8,0].Top  = 110 ;
			ZHUStatus8(1);
			ZHU[9,0].Left = 380 ;
			ZHU[9,0].Top  = 110 ;
			ZHUStatus9(1);
			ZHU[10,0].Left = 500 ;
			ZHU[10,0].Top  = 110 ;
			ZHUStatus10(1);
			ZHU[11,0].Left = 620 ;
			ZHU[11,0].Top  = 110 ;
			ZHUStatus11(1);			
			for(i=0;i<12;i++)
			{
				ZHUDirection[i] = 1 ; 
				ZhuNum = 3 ;
				if(i>0)	{	ZhuNum++ ; }
				if(i>3)	{	ZhuNum++ ; }
				for(j=0;j<ZhuNum;j++)
				{
					ZHU[i,j].Visible = true ;
				}
			}
		}
		private void ZHUStatus0(int Direction)
		{
			//设定珠体0的状态
			switch (Direction)
			{
				case 1:
					//正向上
					ZHU[0,1].Left = ZHU[0,0].Left - 20 ;
					ZHU[0,1].Top  = ZHU[0,0].Top  + 20 ;
					ZHU[0,2].Left = ZHU[0,0].Left ;
					ZHU[0,2].Top  = ZHU[0,0].Top  + 40 ;
					break;
				case 2:
					//向右
					ZHU[0,1].Left = ZHU[0,0].Left - 20 ;
					ZHU[0,1].Top  = ZHU[0,0].Top  - 20 ;
					ZHU[0,2].Left = ZHU[0,0].Left - 40;
					ZHU[0,2].Top  = ZHU[0,0].Top ;
					break;
				case 3:
					//向下
					ZHU[0,1].Left = ZHU[0,0].Left + 20 ;
					ZHU[0,1].Top  = ZHU[0,0].Top  - 20 ;
					ZHU[0,2].Left = ZHU[0,0].Left ;
					ZHU[0,2].Top  = ZHU[0,0].Top  - 40 ;
					break;
				case 4:
					//向左
					ZHU[0,1].Left = ZHU[0,0].Left + 20 ;
					ZHU[0,1].Top  = ZHU[0,0].Top  + 20 ;
					ZHU[0,2].Left = ZHU[0,0].Left + 40;
					ZHU[0,2].Top  = ZHU[0,0].Top ;
					break;
				case 5:
					//反向上
					ZHU[0,1].Left = ZHU[0,0].Left + 20 ;
					ZHU[0,1].Top  = ZHU[0,0].Top  + 20 ;
					ZHU[0,2].Left = ZHU[0,0].Left ;
					ZHU[0,2].Top  = ZHU[0,0].Top  + 40 ;
					break;
				case 6:
					//向右
					ZHU[0,1].Left = ZHU[0,0].Left - 20 ;
					ZHU[0,1].Top  = ZHU[0,0].Top  + 20 ;
					ZHU[0,2].Left = ZHU[0,0].Left - 40;
					ZHU[0,2].Top  = ZHU[0,0].Top ;
					break;
				case 7:
					//向下
					ZHU[0,1].Left = ZHU[0,0].Left - 20 ;
					ZHU[0,1].Top  = ZHU[0,0].Top  - 20 ;
					ZHU[0,2].Left = ZHU[0,0].Left ;
					ZHU[0,2].Top  = ZHU[0,0].Top  - 40 ;
					break;
				case 8:
					//向左
					ZHU[0,1].Left = ZHU[0,0].Left + 20 ;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -