//处理下棋消息 public void handleDownMessage(string content) { int pos = content.IndexOf("|"); int kos = content.IndexOf("@"); string num = content.Substring(0, pos); string bow = content.Substring(kos + 1); string im = content.Substring(pos + 1, 1); AddChessEventArgs arg = new AddChessEventArgs(); arg.Number = num; arg.Im = im; arg.Bow = bow; OnAddChess(this, arg); }
//添加对方下的棋 public void AddChess(object sender, ChessClass.AddChessEventArgs e) { if (this.InvokeRequired) { this.Invoke( new EventHandler <ChessClass.AddChessEventArgs>(this.AddChess), new object[] { sender, e }); } else { string Cplace = e.Number; //获取棋子的名称 string Ccolumn = Cplace.Substring(0, Cplace.IndexOf("*")); //获取棋子所在列数 //获取棋子所在行数 string Crow = Cplace.Substring(Cplace.IndexOf("*") + 1, Cplace.Length - (Cplace.IndexOf("*") + 1)); PictureBox pictureBoxTem = new PictureBox(); //创建一个PictureBox控件 pictureBoxTem.Parent = panel_Check; //设置其父容器 //计算棋子的位置 pictureBoxTem.Location = new Point(Convert.ToInt32(Crow) * 35 + 9, Convert.ToInt32(Ccolumn) * 35 + 9); pictureBoxTem.Name = "pictureBox" + e.Number; //设置棋子的名称 pictureBoxTem.Size = new Size(30, 30); //设置棋子的大小 pictureBoxTem.SizeMode = PictureBoxSizeMode.StretchImage; //记录棋子的类型及位置 note[Convert.ToInt32(Ccolumn), Convert.ToInt32(Crow)] = Convert.ToInt32(e.Im); int num = Int32.Parse(e.Im); //记录棋子的类型 BBow = Int32.Parse(e.Bow); pictureBoxTem.Image = imageList1.Images[num]; //添加棋子图片 pBox_Sign.Visible = true; //设置标识图片的位置 pBox_Sign.Location = new Point(Convert.ToInt32(Crow) * 35 + 20, Convert.ToInt32(Ccolumn) * 35 + 20); pBox_Sign.BringToFront(); if_UPdata = 1; Arithmetic(num, Convert.ToInt32(Ccolumn), Convert.ToInt32(Crow));//对棋子进行计算 if_UPdata = 0; //根据棋子类型显示相应的图片 if (ChildSgin == true) { if (BBow % 2 == 1) { if (label_Left.Text.Trim() == Publec_Class.UserName) { pictureBox_Q_Left.Image = null; pictureBox_Q_Left.Image = Image.FromFile(ClientClass.ImaDir + "\\Image\\黑棋.png"); } else { pictureBox_Q_Right.Image = null; pictureBox_Q_Right.Image = Image.FromFile(ClientClass.ImaDir + "\\Image\\白棋.png"); } } else { if (label_Left.Text.Trim() == Publec_Class.UserName) { pictureBox_Q_Left.Image = null; pictureBox_Q_Left.Image = Image.FromFile(ClientClass.ImaDir + "\\Image\\白棋.png"); } else { pictureBox_Q_Right.Image = null; pictureBox_Q_Right.Image = Image.FromFile(ClientClass.ImaDir + "\\Image\\黑棋.png"); } } ChildSgin = false; } } WhoFisrtDown = true; dropchild = true; }