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

📄 game2dclient.cs

📁 c#网络编程及应用-刘瑞新
💻 CS
📖 第 1 页 / 共 2 页
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

using System.Net;
using System.Net.Sockets;
using System.IO;
using System.Threading;

namespace Game2DClient
{
	/// <summary>
	/// Form1 的摘要说明。
	/// </summary>
	public class Game2DClient : System.Windows.Forms.Form
	{
		private const int NONE = -1;   //背景色
		private const int BLACK =0;    //黑色
		private const int WHITE = 1;   //白色
		private int[,] Game2DGrid = new int [15, 15]; //保存颜色,消点时判断用
        private bool start=false;
        private NetworkStream netStream;
		private StreamReader sr;
		private StreamWriter sw;
		private Thread threadReceive;
		private TcpClient client;
		private bool IsLogin,IsExit;
		private string myName="";
		//private int myNumber=-1;

		private System.Windows.Forms.ImageList imageList1;
		private System.Windows.Forms.PictureBox pictureBox1;
		private System.Windows.Forms.Button buttonExit;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.RadioButton radioButton1;
		private System.Windows.Forms.RadioButton radioButton2;
		private System.Windows.Forms.RadioButton radioButton3;
		private System.Windows.Forms.RadioButton radioButton4;
		private System.Windows.Forms.RadioButton radioButton5;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.Label label7;
		private System.Windows.Forms.Label label8;
		private System.Windows.Forms.Label labelChengJi2;
		private System.Windows.Forms.Label labelChengJi1;
		private System.Windows.Forms.StatusBar statusBar1;
		private System.Windows.Forms.StatusBarPanel statusBarPanel1;
		private System.Windows.Forms.Button buttonStrat;
		private System.Windows.Forms.ListBox listBox1;
		private System.Windows.Forms.TextBox textBox1;
		private System.Windows.Forms.Button buttonHelp;
		private System.Windows.Forms.Button buttonTalk;
		private System.ComponentModel.IContainer components;

		public Game2DClient()
		{

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

			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//
			for(int i = 0; i < 15; i++)
				for(int j= 0; j < 15; j++)
					Game2DGrid[i,j]=NONE;
			this.labelChengJi1.Text=" ";
			this.labelChengJi2.Text=" ";
			this.label7.Text="";
			this.label8.Text="";
			connectServer();
		}

		/// <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()
		{
			this.components = new System.ComponentModel.Container();
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Game2DClient));
			this.imageList1 = new System.Windows.Forms.ImageList(this.components);
			this.pictureBox1 = new System.Windows.Forms.PictureBox();
			this.buttonExit = new System.Windows.Forms.Button();
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.radioButton1 = new System.Windows.Forms.RadioButton();
			this.radioButton2 = new System.Windows.Forms.RadioButton();
			this.radioButton3 = new System.Windows.Forms.RadioButton();
			this.radioButton4 = new System.Windows.Forms.RadioButton();
			this.radioButton5 = new System.Windows.Forms.RadioButton();
			this.labelChengJi2 = new System.Windows.Forms.Label();
			this.label6 = new System.Windows.Forms.Label();
			this.buttonStrat = new System.Windows.Forms.Button();
			this.labelChengJi1 = new System.Windows.Forms.Label();
			this.label4 = new System.Windows.Forms.Label();
			this.label7 = new System.Windows.Forms.Label();
			this.label8 = new System.Windows.Forms.Label();
			this.statusBar1 = new System.Windows.Forms.StatusBar();
			this.statusBarPanel1 = new System.Windows.Forms.StatusBarPanel();
			this.listBox1 = new System.Windows.Forms.ListBox();
			this.textBox1 = new System.Windows.Forms.TextBox();
			this.buttonHelp = new System.Windows.Forms.Button();
			this.buttonTalk = new System.Windows.Forms.Button();
			this.groupBox1.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.statusBarPanel1)).BeginInit();
			this.SuspendLayout();
			// 
			// imageList1
			// 
			this.imageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth24Bit;
			this.imageList1.ImageSize = new System.Drawing.Size(20, 20);
			this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
			this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
			// 
			// pictureBox1
			// 
			this.pictureBox1.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("pictureBox1.BackgroundImage")));
			this.pictureBox1.Cursor = System.Windows.Forms.Cursors.Arrow;
			this.pictureBox1.Location = new System.Drawing.Point(134, 12);
			this.pictureBox1.Name = "pictureBox1";
			this.pictureBox1.Size = new System.Drawing.Size(344, 350);
			this.pictureBox1.TabIndex = 0;
			this.pictureBox1.TabStop = false;
			this.pictureBox1.Paint += new System.Windows.Forms.PaintEventHandler(this.pictureBox1_Paint);
			this.pictureBox1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseDown);
			// 
			// buttonExit
			// 
			this.buttonExit.Location = new System.Drawing.Point(22, 426);
			this.buttonExit.Name = "buttonExit";
			this.buttonExit.TabIndex = 1;
			this.buttonExit.Text = "退出";
			this.buttonExit.Click += new System.EventHandler(this.buttonExit_Click);
			// 
			// groupBox1
			// 
			this.groupBox1.Controls.Add(this.radioButton1);
			this.groupBox1.Controls.Add(this.radioButton2);
			this.groupBox1.Controls.Add(this.radioButton3);
			this.groupBox1.Controls.Add(this.radioButton4);
			this.groupBox1.Controls.Add(this.radioButton5);
			this.groupBox1.Location = new System.Drawing.Point(20, 80);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(80, 200);
			this.groupBox1.TabIndex = 2;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "难度级别";
			// 
			// radioButton1
			// 
			this.radioButton1.Checked = true;
			this.radioButton1.Location = new System.Drawing.Point(16, 32);
			this.radioButton1.Name = "radioButton1";
			this.radioButton1.Size = new System.Drawing.Size(48, 24);
			this.radioButton1.TabIndex = 0;
			this.radioButton1.TabStop = true;
			this.radioButton1.Text = "1级";
			this.radioButton1.CheckedChanged += new System.EventHandler(this.radioButton1_CheckedChanged);
			// 
			// radioButton2
			// 
			this.radioButton2.Location = new System.Drawing.Point(16, 64);
			this.radioButton2.Name = "radioButton2";
			this.radioButton2.Size = new System.Drawing.Size(48, 24);
			this.radioButton2.TabIndex = 0;
			this.radioButton2.Text = "2级";
			this.radioButton2.CheckedChanged += new System.EventHandler(this.radioButton2_CheckedChanged);
			// 
			// radioButton3
			// 
			this.radioButton3.Location = new System.Drawing.Point(16, 96);
			this.radioButton3.Name = "radioButton3";
			this.radioButton3.Size = new System.Drawing.Size(48, 24);
			this.radioButton3.TabIndex = 0;
			this.radioButton3.Text = "3级";
			this.radioButton3.CheckedChanged += new System.EventHandler(this.radioButton3_CheckedChanged);
			// 
			// radioButton4
			// 
			this.radioButton4.Location = new System.Drawing.Point(16, 128);
			this.radioButton4.Name = "radioButton4";
			this.radioButton4.Size = new System.Drawing.Size(48, 24);
			this.radioButton4.TabIndex = 0;
			this.radioButton4.Text = "4级";
			this.radioButton4.CheckedChanged += new System.EventHandler(this.radioButton4_CheckedChanged);
			// 
			// radioButton5
			// 
			this.radioButton5.Location = new System.Drawing.Point(16, 160);
			this.radioButton5.Name = "radioButton5";
			this.radioButton5.Size = new System.Drawing.Size(48, 24);
			this.radioButton5.TabIndex = 0;
			this.radioButton5.Text = "5级";
			this.radioButton5.CheckedChanged += new System.EventHandler(this.radioButton5_CheckedChanged);
			// 
			// labelChengJi2
			// 
			this.labelChengJi2.Location = new System.Drawing.Point(544, 304);
			this.labelChengJi2.Name = "labelChengJi2";
			this.labelChengJi2.Size = new System.Drawing.Size(72, 24);
			this.labelChengJi2.TabIndex = 8;
			this.labelChengJi2.Text = "0";
			// 
			// label6
			// 
			this.label6.Location = new System.Drawing.Point(498, 304);
			this.label6.Name = "label6";
			this.label6.Size = new System.Drawing.Size(48, 24);
			this.label6.TabIndex = 7;
			this.label6.Text = "得分:";
			// 
			// buttonStrat
			// 
			this.buttonStrat.Location = new System.Drawing.Point(22, 380);
			this.buttonStrat.Name = "buttonStrat";
			this.buttonStrat.TabIndex = 1;
			this.buttonStrat.Text = "开始";
			this.buttonStrat.Click += new System.EventHandler(this.buttonStart_Click);
			// 
			// labelChengJi1
			// 
			this.labelChengJi1.Location = new System.Drawing.Point(544, 110);
			this.labelChengJi1.Name = "labelChengJi1";
			this.labelChengJi1.Size = new System.Drawing.Size(72, 24);
			this.labelChengJi1.TabIndex = 10;
			this.labelChengJi1.Text = "0";
			// 
			// label4
			// 
			this.label4.Location = new System.Drawing.Point(498, 110);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(48, 24);
			this.label4.TabIndex = 9;
			this.label4.Text = "得分:";
			// 
			// label7
			// 
			this.label7.Location = new System.Drawing.Point(498, 74);
			this.label7.Name = "label7";
			this.label7.Size = new System.Drawing.Size(118, 24);
			this.label7.TabIndex = 11;
			this.label7.Text = "对方(白方)";
			// 
			// label8
			// 
			this.label8.Location = new System.Drawing.Point(498, 272);
			this.label8.Name = "label8";
			this.label8.Size = new System.Drawing.Size(118, 24);
			this.label8.TabIndex = 11;
			this.label8.Text = "我方(黑方)";
			// 
			// statusBar1
			// 
			this.statusBar1.Location = new System.Drawing.Point(0, 468);
			this.statusBar1.Name = "statusBar1";
			this.statusBar1.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {
																						  this.statusBarPanel1});
			this.statusBar1.ShowPanels = true;
			this.statusBar1.Size = new System.Drawing.Size(630, 22);
			this.statusBar1.TabIndex = 16;
			this.statusBar1.Text = "statusBar1";
			// 
			// statusBarPanel1
			// 
			this.statusBarPanel1.Text = "状态行";
			this.statusBarPanel1.Width = 625;
			// 
			// listBox1
			// 
			this.listBox1.ItemHeight = 15;
			this.listBox1.Location = new System.Drawing.Point(132, 376);
			this.listBox1.Name = "listBox1";
			this.listBox1.Size = new System.Drawing.Size(474, 49);
			this.listBox1.TabIndex = 17;
			// 
			// textBox1
			// 
			this.textBox1.Location = new System.Drawing.Point(132, 442);
			this.textBox1.Name = "textBox1";
			this.textBox1.Size = new System.Drawing.Size(416, 21);
			this.textBox1.TabIndex = 18;
			this.textBox1.Text = "";
			// 
			// buttonHelp
			// 
			this.buttonHelp.Location = new System.Drawing.Point(22, 334);
			this.buttonHelp.Name = "buttonHelp";
			this.buttonHelp.TabIndex = 1;
			this.buttonHelp.Text = "帮助";
			this.buttonHelp.Click += new System.EventHandler(this.buttonHelp_Click);
			// 
			// buttonTalk
			// 
			this.buttonTalk.BackColor = System.Drawing.SystemColors.Control;
			this.buttonTalk.ForeColor = System.Drawing.SystemColors.ControlText;
			this.buttonTalk.Location = new System.Drawing.Point(556, 442);
			this.buttonTalk.Name = "buttonTalk";
			this.buttonTalk.Size = new System.Drawing.Size(50, 23);
			this.buttonTalk.TabIndex = 19;
			this.buttonTalk.Text = "发送";
			this.buttonTalk.Click += new System.EventHandler(this.buttonTalk_Click);
			// 
			// Game2DClient
			// 
			this.AutoScale = false;
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(630, 490);
			this.Controls.Add(this.buttonTalk);
			this.Controls.Add(this.textBox1);
			this.Controls.Add(this.listBox1);
			this.Controls.Add(this.statusBar1);
			this.Controls.Add(this.label7);
			this.Controls.Add(this.labelChengJi1);
			this.Controls.Add(this.label4);
			this.Controls.Add(this.labelChengJi2);
			this.Controls.Add(this.label6);
			this.Controls.Add(this.groupBox1);
			this.Controls.Add(this.pictureBox1);
			this.Controls.Add(this.buttonExit);
			this.Controls.Add(this.buttonStrat);
			this.Controls.Add(this.label8);
			this.Controls.Add(this.buttonHelp);
			this.Cursor = System.Windows.Forms.Cursors.Hand;
			this.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
			this.ImeMode = System.Windows.Forms.ImeMode.Off;
			this.MaximizeBox = false;
			this.Name = "Game2DClient";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "Game2D网络游戏";
			this.Closing += new System.ComponentModel.CancelEventHandler(this.Game2DClient_Closing);
			this.groupBox1.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.statusBarPanel1)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// 应用程序的主入口点。
		/// </summary>
		[STAThread]

⌨️ 快捷键说明

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