Exemplo n.º 1
0
 private void pictureBox_Close_Click(object sender, EventArgs e)
 {
     ChessClass.Client cc = Program.PublicClientObject;
     cc.CloseConnection();
     if (Out == true)
     {
         listener.Close();
     }
     ConnHandle = 0;
     if (GIP.Trim().Length > 4)
     {
         temMsg2.msgCommand = MsgCommand.ExitJoin;
         udpSocket1.Send(IPAddress.Parse(GIP), 11001, new ClassSerializers().SerializeBinary(temMsg2).ToArray());
         MessageBox.Show("是否关闭窗体");
     }
     this.DialogResult = DialogResult.OK;
     this.Close();
 }
Exemplo n.º 2
0
        //点击棋盘
        public void asd(object sender, EventArgs e)
        {
            if (dropchild == false)//如果当前用户已下完棋
            {
                return;
            }
            if ((Mouse_X <= 30.0 / 2.0) || (Mouse_Y <= 30.0 / 2.0))//如果落子点超出落子范围
            {
                return;
            }
            if (CanDown == true)       //如果已开始下棋
            {
                if (Conqueror == true) //如果本棋局已有赢家
                {
                    if (CKind == 0)    //黑棋赢
                    {
                        Bwin();
                    }
                    if (CKind == 1)//白棋赢
                    {
                        Wwin();
                    }
                    return;
                }
                if (WhoFisrtDown == true)                                          //对方先落子
                {
                    int Column = Convert.ToInt32(Math.Round((Mouse_X - 30) / 35)); //获取棋子在棋盘中的列数
                    int Row    = Convert.ToInt32(Math.Round((Mouse_Y - 30) / 35)); //获取棋子在棋盘中的行数
                    int bw     = 0;

                    if (note[Convert.ToInt32(Row), Convert.ToInt32(Column)] >= 0)//如果当前已有棋子
                    {
                        return;
                    }
                    PictureBox pictureBoxTem = new PictureBox();                       //动态创建一个图片控件
                    pictureBoxTem.Parent   = panel_Check;                              //设置其父容器
                    pictureBoxTem.Location = new Point(Column * 35 + 9, Row * 35 + 9); //设置图片控件的位置
                    //设置图片控件的名称
                    pictureBoxTem.Name = "pictureBox" + Row.ToString() + "*" + Column.ToString();
                    //设置标识图片的位置(用于标识最后下的棋子)
                    pBox_Sign.Location = new Point(Column * 35 + 20, Row * 35 + 20);

                    pictureBoxTem.Size     = new Size(30, 30);                //设置棋子的大小
                    pictureBoxTem.SizeMode = PictureBoxSizeMode.StretchImage; //设置图像的样式
                    ChessClass.Client cc = Program.PublicClientObject;
                    BBow++;
                    pBox_Sign.Visible = true; //使标识图片可见
                    pBox_Sign.BringToFront(); //如果当前的棋子是黑棋
                    if (BBow % 2 == 1)
                    {
                        label_Genre.Text    = "黑棋";
                        label_Genre.Tag     = 0;
                        pictureBoxTem.Image = imageList1.Images[0]; //显示当前棋子为黑棋
                        bw = 0;                                     //标识当前用户为黑棋
                        note[Row, Column] = 0;                      //记录当前棋子的落子位置
                        //将当前下的棋子信息发送给对方玩家
                        cc.SendMessage("Down#" + Row.ToString() + "*" + Column.ToString() + "|" + "0" + "@" + BBow.ToString());
                    }
                    else
                    {
                        label_Genre.Text    = "白棋";
                        label_Genre.Tag     = 1;
                        pictureBoxTem.Image = imageList1.Images[1]; //显示当前棋子为白棋
                        bw = 1;                                     //标识当前用户为白棋
                        note[Row, Column] = 1;                      //记录当前棋子的落子位置
                        //将当前下的棋子信息发送给对方玩家
                        cc.SendMessage("Down#" + Row.ToString() + "*" + Column.ToString() + "|" + "1" + "@" + BBow.ToString());
                    }
                    //根据棋子类型显示相应的图片
                    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;
                    }
                    note[Row, Column] = bw;
                    if_UPdata         = 0;
                    Arithmetic(bw, Row, Column);//计算当前下的棋子是否赢
                }
                else
                {
                    MessageBox.Show("对方还没有落子!");
                    dropchild = true;
                    return;
                }
            }
            else
            {
                MessageBox.Show("本盘棋局没有开始无法下棋!");
                dropchild = true;
                return;
            }
            dropchild = false;
        }
Exemplo n.º 3
0
        private void pboxStart_Click(object sender, EventArgs e)
        {
            pboxStart.Image = null;//清空“开始”按钮
            //设置“开始”按钮为灰度
            pboxStart.Image   = Image.FromFile(ClientClass.ImaDir + "\\Image\\开始按钮灰.png");
            pboxStart.Enabled = false;//使“开始”按钮不可用

            switch (ConnHandle)
            {
            case 1:    //第1次单击“开始”按钮,用于连接对方并开始下棋
            {
                ChessClass.Client cc = Program.PublicClientObject;
                if (cc.Connected)         //如果已开启了连接
                {
                    cc.CloseConnection(); //断开连接
                }

                try
                {
                    if (GIP == "")        //如果没有对方的IP地址
                    {
                        break;
                    }
                    cc.ConnectServer(GIP, int.Parse("11003"));        //建立连接
                }
                catch
                {
                    MessageBox.Show("连接服务器失败");        //如果连接失败,使“开始”按钮可用
                    this.pboxStart.Image   = null;
                    this.pboxStart.Enabled = true;
                    this.pboxStart.Image   = Image.FromFile(ClientClass.ImaDir + "\\Image\\开始按钮.png");
                    return;
                }
                WhoFisrtDown = false;          //设置谁先下棋
                cc.SendMessage("FiDn" + "Me"); //发送信息
                CanDown    = true;
                ConnHandle = 2;
                break;
            }

            case 2:    //第2次及其以后单击,重新开始游戏
            {
                CanAgin      = true;
                WhoFisrtDown = false;
                dropchild    = true;
                CanDown      = true;
                Conqueror    = false;
                ChessClass.Client cc = Program.PublicClientObject;
                cc.SendMessage("FiDn" + "Me");        //发送信息,是否重新下棋
                if (Agin_if == false)
                {
                    cc.SendMessage("Agin#" + "OK?");
                    Agin();        //设置重新下棋的初始值
                }
                else
                {
                    Agin_if = false;
                    if (panel_Check.Controls.Count > 10)
                    {
                        Agin();
                    }
                }
                BBow = BBow + 1;
                pBox_Sign.Visible = false;        //使棋子的标识图片不可见
                Conqueror         = false;
                break;
            }
            }
            childSgin = true;
        }