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

📄 form1.cs

📁 这是我的第一个,里面有好多个游戏,要是不对给我留言,
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace 游戏
{
	/// <summary>
	/// Form1 的摘要说明。
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Button button2;
		private System.Windows.Forms.Button button3;
		private System.Windows.Forms.Button button4;
		private System.Windows.Forms.Button button5;
		private System.Windows.Forms.Button button6;
		private System.Windows.Forms.Button button7;
		private System.Windows.Forms.Button button8;
		private System.Windows.Forms.Button button9;
		private System.Windows.Forms.Label label1;
		int [,] a=new int[4,4];
		int count1;
		double startTime,endTime;
		private System.Windows.Forms.Button btnStart;
		private System.Windows.Forms.Button btnEnd;
		private System.Windows.Forms.Label lblTime;
		private System.Windows.Forms.Label lblCountTi;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

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

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

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

		#region Windows 窗体设计器生成的代码
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.button1 = new System.Windows.Forms.Button();
			this.button2 = new System.Windows.Forms.Button();
			this.button3 = new System.Windows.Forms.Button();
			this.button4 = new System.Windows.Forms.Button();
			this.button5 = new System.Windows.Forms.Button();
			this.button6 = new System.Windows.Forms.Button();
			this.button7 = new System.Windows.Forms.Button();
			this.button8 = new System.Windows.Forms.Button();
			this.button9 = new System.Windows.Forms.Button();
			this.btnStart = new System.Windows.Forms.Button();
			this.btnEnd = new System.Windows.Forms.Button();
			this.label1 = new System.Windows.Forms.Label();
			this.lblTime = new System.Windows.Forms.Label();
			this.lblCountTi = new System.Windows.Forms.Label();
			this.SuspendLayout();
			// 
			// button1
			// 
			this.button1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.button1.Location = new System.Drawing.Point(112, 120);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(32, 23);
			this.button1.TabIndex = 0;
			this.button1.Text = "1";
			this.button1.Click += new System.EventHandler(this.MixedControl_Click);
			// 
			// button2
			// 
			this.button2.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.button2.Location = new System.Drawing.Point(144, 120);
			this.button2.Name = "button2";
			this.button2.Size = new System.Drawing.Size(32, 23);
			this.button2.TabIndex = 1;
			this.button2.Text = "2";
			this.button2.Click += new System.EventHandler(this.MixedControl_Click);
			// 
			// button3
			// 
			this.button3.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.button3.Location = new System.Drawing.Point(176, 120);
			this.button3.Name = "button3";
			this.button3.Size = new System.Drawing.Size(32, 23);
			this.button3.TabIndex = 2;
			this.button3.Text = "3";
			this.button3.Click += new System.EventHandler(this.MixedControl_Click);
			// 
			// button4
			// 
			this.button4.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.button4.Location = new System.Drawing.Point(112, 144);
			this.button4.Name = "button4";
			this.button4.Size = new System.Drawing.Size(32, 23);
			this.button4.TabIndex = 3;
			this.button4.Text = "4";
			this.button4.Click += new System.EventHandler(this.MixedControl_Click);
			// 
			// button5
			// 
			this.button5.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.button5.Location = new System.Drawing.Point(144, 144);
			this.button5.Name = "button5";
			this.button5.Size = new System.Drawing.Size(32, 23);
			this.button5.TabIndex = 4;
			this.button5.Text = "5";
			this.button5.Click += new System.EventHandler(this.MixedControl_Click);
			// 
			// button6
			// 
			this.button6.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.button6.Location = new System.Drawing.Point(176, 144);
			this.button6.Name = "button6";
			this.button6.Size = new System.Drawing.Size(32, 23);
			this.button6.TabIndex = 5;
			this.button6.Text = "6";
			this.button6.Click += new System.EventHandler(this.MixedControl_Click);
			// 
			// button7
			// 
			this.button7.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.button7.Location = new System.Drawing.Point(112, 168);
			this.button7.Name = "button7";
			this.button7.Size = new System.Drawing.Size(32, 23);
			this.button7.TabIndex = 6;
			this.button7.Text = "7";
			this.button7.Click += new System.EventHandler(this.MixedControl_Click);
			// 
			// button8
			// 
			this.button8.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.button8.Location = new System.Drawing.Point(144, 168);
			this.button8.Name = "button8";
			this.button8.Size = new System.Drawing.Size(32, 23);
			this.button8.TabIndex = 7;
			this.button8.Text = "8";
			this.button8.Click += new System.EventHandler(this.MixedControl_Click);
			// 
			// button9
			// 
			this.button9.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.button9.Location = new System.Drawing.Point(176, 168);
			this.button9.Name = "button9";
			this.button9.Size = new System.Drawing.Size(32, 23);
			this.button9.TabIndex = 8;
			this.button9.Text = "9";
			this.button9.Click += new System.EventHandler(this.MixedControl_Click);
			// 
			// btnStart
			// 
			this.btnStart.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.btnStart.Location = new System.Drawing.Point(88, 224);
			this.btnStart.Name = "btnStart";
			this.btnStart.TabIndex = 13;
			this.btnStart.Text = " 开始";
			this.btnStart.Click += new System.EventHandler(this.btnStart_Click);
			// 
			// btnEnd
			// 
			this.btnEnd.Enabled = false;
			this.btnEnd.Location = new System.Drawing.Point(168, 224);
			this.btnEnd.Name = "btnEnd";
			this.btnEnd.TabIndex = 12;
			this.btnEnd.Text = "结束";
			this.btnEnd.Click += new System.EventHandler(this.btnEnd_Click);
			// 
			// label1
			// 
			this.label1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label1.Location = new System.Drawing.Point(96, 64);
			this.label1.Name = "label1";
			this.label1.TabIndex = 11;
			this.label1.Text = "九格益智游戏";
			// 
			// lblTime
			// 
			this.lblTime.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.lblTime.Location = new System.Drawing.Point(232, 104);
			this.lblTime.Name = "lblTime";
			this.lblTime.TabIndex = 9;
			this.lblTime.Text = "秒数:";
			// 
			// lblCountTi
			// 
			this.lblCountTi.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.lblCountTi.Location = new System.Drawing.Point(232, 160);
			this.lblCountTi.Name = "lblCountTi";
			this.lblCountTi.TabIndex = 10;
			this.lblCountTi.Text = "次数:";
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.BackColor = System.Drawing.Color.PaleGoldenrod;
			this.ClientSize = new System.Drawing.Size(384, 355);
			this.Controls.Add(this.lblCountTi);
			this.Controls.Add(this.lblTime);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.btnEnd);
			this.Controls.Add(this.btnStart);
			this.Controls.Add(this.button9);
			this.Controls.Add(this.button8);
			this.Controls.Add(this.button7);
			this.Controls.Add(this.button6);
			this.Controls.Add(this.button5);
			this.Controls.Add(this.button4);
			this.Controls.Add(this.button3);
			this.Controls.Add(this.button2);
			this.Controls.Add(this.button1);
			this.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.Name = "Form1";
			this.Text = "Form1";
			this.Click += new System.EventHandler(this.Form1_Load);
			this.Load += new System.EventHandler(this.Form1_Load);
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// 应用程序的主入口点。
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}

		void display()
		{
			button1.BackColor=(a[1,1]==1)? Color.Red:Color.Blue;
			button2.BackColor=(a[1,2]==1)? Color.Red:Color.Blue;
			button3.BackColor=(a[1,3]==1)? Color.Red:Color.Blue;
			button4.BackColor=(a[2,1]==1)? Color.Red:Color.Blue;
			button5.BackColor=(a[2,2]==1)? Color.Red:Color.Blue;
			button6.BackColor=(a[2,3]==1)? Color.Red:Color.Blue;
			button7.BackColor=(a[3,1]==1)? Color.Red:Color.Blue;
			button8.BackColor=(a[3,2]==1)? Color.Red:Color.Blue;
			button9.BackColor=(a[3,3]==1)? Color.Red:Color.Blue;
		}
		
		int getsec(DateTime d)
		{
			int h=d.Hour;
			int m=d.Minute;
			int s=d.Second;
			return (h*60+m)*60+s;
		}

		void check()
		{
			int sum=0;
			count1+=1;
			endTime=getsec(DateTime.Now);
			lblTime.Text=String.Format("秒数:{0}",endTime-startTime);
			lblCountTi.Text=String.Format("次数:{0}次",count1);
			for(int i=1;i<4;i++)
				for(int j=1;j<4;j++)
					sum+=a[i,j];
			if(sum==7&&a[2,2]==-1)
				MessageBox.Show("恭喜! 过关。。。");
			lblCountTi.Text=String.Format("次数:{0}次",count1);
		}

		private void MixedControl_Click(object sender,System.EventArgs e)
		{
			switch (((Button) sender).TabIndex+1)
			{
				case 1:
					a[1,1]=-a[1,1];
					a[1,2]=-a[1,2];
					a[2,2]=-a[2,2];
					a[2,1]=-a[2,1];
					break;
				case 2:
					a[1,2]=-a[1,2];
					a[1,1]=-a[1,1];
					a[1,3]=-a[1,3];
					break;
				case 3:
					a[1,2]=-a[1,2];
					a[1,3]=-a[1,3];
					a[2,2]=-a[2,2];
					a[2,3]=-a[2,3];
					break;
				case 4:
					a[2,1]=-a[2,1];
					a[1,1]=-a[1,1];
					a[3,1]=-a[3,1];
					break;
				case 5:
					a[2,2]=-a[2,2];
					a[1,2]=-a[1,2];
					a[2,1]=-a[2,1];
					a[2,3]=-a[2,3];
					a[3,2]=-a[3,2];
					break;
				case 6:
					a[1,3]=-a[1,3];
					a[2,3]=-a[2,3];
					a[3,3]=-a[3,3];
					break;
				case 7:
					a[2,1]=-a[2,1];
					a[3,1]=-a[3,1];
					a[3,2]=-a[3,2];
					a[2,2]=-a[2,2];
					break;
				case 8:
					a[3,1]=-a[3,1];
					a[3,2]=-a[3,2];
					a[3,3]=-a[3,3];
					break;
				case 9:
					a[2,2]=-a[2,2];
					a[2,3]=-a[2,3];
					a[3,2]=-a[3,2];
					a[3,3]=-a[3,3];
					break;
			}

			display();

			check();
		}

		private void Form1_Load(object sender, System.EventArgs e)
		{
			btnStart.Enabled=true;
			btnEnd.Enabled=false;
		
		}

		private void btnStart_Click(object sender,System.EventArgs e)
		{
			startTime=getsec(DateTime.Now);
            count1=0;
			btnStart.Enabled=false;
			btnEnd.Enabled=true;
			Random suiji=new Random();
			for(int i=1;i<4;i++)
				for(int j=1;j<4;j++)
				{
					
					if(suiji.Next(1,10)>5)a[i,j]=1;
					else a[i,j]=-1;
				}
						
			display();
		}
		private void btnEnd_Click(object sender,System.EventArgs e)
		{
			Application.Exit();
		}

		
	}
}

⌨️ 快捷键说明

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