Ejemplo n.º 1
0
        private void UcChessPiece_MouseUp(object sender, MouseEventArgs e)
        {
            if (UcChessBoard.IsCapturedMode)
            {
                return;
            }
            UcChessBoard Board = (UcChessBoard)this.Parent;//Lấy bàn cờ


            if (this.Side == Board.OwnSide || Board.GameMode == GameMode.VsHuman)
            {
                if ((this.Side == ChessSide.White && Board.WhiteToMove == true) || (this.Side == ChessSide.Black && Board.WhiteToMove == false))
                {
                    Board.UnHighlightMoves();
                    //*********************************Lấy tọa độ ô cờ***********************
                    //Lấy hai vị trí trọng tâm của PieceSize/2
                    int a = (this.Location.X + (this._PieceSize / 2)) / this._CellSize;
                    int b = (this.Location.Y + (this._PieceSize / 2)) / this._CellSize;

                    UcChessCell ct = new UcChessCell();

                    ///////CODECHANGE NGÀY 0605
                    string n;
                    int    NewPos_X;
                    int    NewPos_Y;
                    if (Board.OwnSide == ChessSide.White)
                    {
                        n        = Convert.ToChar(65 + a).ToString() + (8 - b);//65 là kí tự A
                        NewPos_X = a + 1;
                        NewPos_Y = 8 - b;
                    }
                    else
                    {
                        n        = Convert.ToChar(64 + 8 - a).ToString() + (b + 1);//65 là kí tự A
                        NewPos_X = 8 - a;
                        NewPos_Y = b + 1;
                    }

                    Point NewPos = new Point(NewPos_X, NewPos_Y);
                    Point CurPos = new Point(this._PositionX, this._PositionY);


                    Board.DoMove(this, new clsMove(CurPos, NewPos)); //Di chuyển quân cờ
                }
            }
        }