示例#1
0
        static public void Chesspiece_Move(Button Source, Button Destination, ChessBoard chessBoard)
        {
            //xử lý nhập thành
            if (chessBoard.MyTurn && chessBoard.vua_trang)
            {
                if (Source.Text == "king" && (Destination.Location.X / chessBoard.widthCell == 2 || Destination.Location.X / chessBoard.widthCell == 6))
                {
                    King.ExecuteCastling(chessBoard, Destination.Location.X / chessBoard.widthCell);
                    return;
                }
            }
            else if (!chessBoard.MyTurn && chessBoard.vua_den)
            {
                if (Source.Text == "king" && (Destination.Location.X / chessBoard.widthCell == 2 || Destination.Location.X / chessBoard.widthCell == 6))
                {
                    King.ExecuteCastling(chessBoard, Destination.Location.X / chessBoard.widthCell);
                    return;
                }
            }

            if (Source.Text == "rook" || Source.Text == "king")
            {
                chessBoard.updateCastling(Source);
            }


            Destination.Text      = Source.Text;
            Destination.ForeColor = Source.ForeColor;
            Source.Text           = "";
            Source.ForeColor      = Color.AliceBlue;

            chessBoard.movementInfos.Add(chessBoard.saveMovementInfor(Source, Destination));
            Destination.FlatAppearance.BorderColor = Color.Blue;

            PictureInsert(Source);
            PictureInsert(Destination);
        }
示例#2
0
        static public void Chesspiece_Move(Button Source, Button Destination, ChessBoard chessBoard)
        {
            //xử lý nhập thành____________________________________________________________________
            if (chessBoard.MyTurn && chessBoard.vua_trang)
            {
                if (Source.Text == "king" && (Destination.Location.X / chessBoard.widthCell == 2 || Destination.Location.X / chessBoard.widthCell == 6))
                {
                    King.ExecuteCastling(chessBoard, Destination.Location.X / chessBoard.widthCell);
                    chessBoard.movementInfos.Add(chessBoard.saveMovementInfor2(Source, Destination.Location.X / chessBoard.widthCell));
                    return;
                }
            }
            else if (!chessBoard.MyTurn && chessBoard.vua_den)
            {
                if (Source.Text == "king" && (Destination.Location.X / chessBoard.widthCell == 2 || Destination.Location.X / chessBoard.widthCell == 6))
                {
                    King.ExecuteCastling(chessBoard, Destination.Location.X / chessBoard.widthCell);
                    chessBoard.movementInfos.Add(chessBoard.saveMovementInfor2(Source, Destination.Location.X / chessBoard.widthCell));
                    return;
                }
            }
            if (Source.Text == "rook" || Source.Text == "king")
            {
                chessBoard.updateCastling(Source);
            }
            //_______________________________________________________________________________________

            chessBoard.movementInfos.Add(chessBoard.saveMovementInfor(Source, Destination));
            //thực hiện di chuyển
            Destination.Text      = Source.Text;
            Destination.ForeColor = Source.ForeColor;
            Source.Text           = "";
            Source.ForeColor      = Color.AliceBlue;

            Destination.FlatAppearance.BorderColor = Color.Blue;
            Source.FlatAppearance.BorderColor      = Color.Blue;


            //xử lý phong cấp tốt_________________________________________________________________________
            if (Destination.Text == "pawn")
            {
                if (chessBoard.HinhThucChoi == 2 && !chessBoard.MyTurn) // đánh với máy
                {
                    int indexY = Destination.Location.Y / Destination.Size.Height;
                    if (/*indexY == 0 ||*/ indexY == 7)
                    {
                        Destination.Text = "queen";
                    }
                }
                else
                {
                    int indexY = Destination.Location.Y / Destination.Size.Height;
                    if (indexY == 0 || indexY == 7)
                    {
                        int indexX = Destination.Location.X / Destination.Size.Width;
                        chessBoard.promotionPawn = indexX;
                        new PromotionPawn(chessBoard).ShowDialog();
                        chessBoard.promotionPawn = -1;
                    }
                }
            }
            //__________________________________________________________________________________________

            PictureInsert(Source);
            PictureInsert(Destination);
        }