Exemplo n.º 1
0
        /// <summary>
        /// chưa chạy được!
        /// </summary>
        /// <returns></returns>
        public void undo()
        {
            if (movementInfos.Count == 0)
            {
                return;
            }

            MovementInfo movementInfo      = this.movementInfos[this.movementInfos.Count - 1];
            int          SourceIndexX      = movementInfo.Src.X / this.cells[0, 0].Size.Width;
            int          SourceIndexY      = movementInfo.Src.Y / this.cells[0, 0].Size.Height;
            int          DestinationIndexX = movementInfo.Dst.X / this.cells[0, 0].Size.Width;
            int          DestinationIndexY = movementInfo.Dst.Y / this.cells[0, 0].Size.Height;

            //Nhập thành
            if (movementInfo.srcText == "nhapthanh")
            {
                King.ExecuteCastlingReverse(this, int.Parse(movementInfo.dstText));
            }
            else if (movementInfo.srcText == "rook" || movementInfo.dstText == "king")
            {
                updateCastling(cells[SourceIndexX, SourceIndexY], true);
            }

            this.cells[SourceIndexX, SourceIndexY].Text           = movementInfo.srcText;
            this.cells[DestinationIndexX, DestinationIndexY].Text = movementInfo.dstText;
            if (movementInfos.Count % 2 == 0) // bên kia đánh
            {
                this.cells[SourceIndexX, SourceIndexY].ForeColor = Color.Black;
                if (cells[DestinationIndexX, DestinationIndexY].Text != "")
                {
                    this.cells[DestinationIndexX, DestinationIndexY].ForeColor = Color.Red;
                }
                else
                {
                    this.cells[DestinationIndexX, DestinationIndexY].ForeColor = Color.AliceBlue;
                }
            }
            else
            {
                this.cells[SourceIndexX, SourceIndexY].ForeColor = Color.Red;
                if (cells[DestinationIndexX, DestinationIndexY].Text != "")
                {
                    this.cells[DestinationIndexX, DestinationIndexY].ForeColor = Color.Black;
                }
                else
                {
                    this.cells[DestinationIndexX, DestinationIndexY].ForeColor = Color.AliceBlue;
                }
            }

            ReadytoAttack = false;
            MyTurn        = !MyTurn;
            ResetBoderColor(this);
            cells[SourceIndexX, SourceIndexY].FlatAppearance.BorderColor           = Color.Blue;
            cells[DestinationIndexX, DestinationIndexY].FlatAppearance.BorderColor = Color.Blue;
            PictureInsert(cells[SourceIndexX, SourceIndexY]);
            PictureInsert(cells[DestinationIndexX, DestinationIndexY]);
            //this.Enabled = true;

            movementInfos.RemoveAt(movementInfos.Count - 1);
        }
Exemplo n.º 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);
        }