Ejemplo n.º 1
0
        public override bool Move(BoardCell destinationCell)
        {
            int cellsToMoveUp    = CurrentCell.YLoc - destinationCell.YLoc;
            int cellsToMoveDown  = destinationCell.YLoc - CurrentCell.YLoc;
            int cellsToMoveLeft  = CurrentCell.XLoc - destinationCell.XLoc;
            int cellsToMoveRight = destinationCell.XLoc - CurrentCell.XLoc;
            // can only move two spaces down on the first move.
            int maxCellsToMove = FirstMove ? ChessBoard.CellSpace * 2 : ChessBoard.CellSpace;

            if (IsPathToDestObstructed(destinationCell))
            {
                return(false);
            }

            if (destinationCell.Occupied)
            {
                return(Take(destinationCell));
            }

            if (Player.Colour == Game.PlayerColour.White)
            {
                if ((cellsToMoveDown > 0 && cellsToMoveDown <= maxCellsToMove &&
                     (cellsToMoveLeft == 0 && cellsToMoveRight == 0)) ||
                    (cellsToMoveDown == 0 && cellsToMoveLeft == ChessBoard.CellSpace) ||
                    (cellsToMoveDown == 0 && cellsToMoveRight == ChessBoard.CellSpace))
                {
                    CurrentCell.RemoveChessPiece();        // Remove this piece from this cell
                    destinationCell.PlaceChessPiece(this); // Add this piece to dest cell
                    CurrentCell = destinationCell;
                    FirstMove   = false;
                    return(true);
                }
                return(false);
            }
            else // Player is black
            {
                if ((cellsToMoveUp > 0 && cellsToMoveUp <= maxCellsToMove &&
                     (cellsToMoveLeft == 0 && cellsToMoveRight == 0)) ||
                    (cellsToMoveDown == 0 && cellsToMoveLeft == ChessBoard.CellSpace) ||
                    (cellsToMoveDown == 0 && cellsToMoveRight == ChessBoard.CellSpace))
                {
                    CurrentCell.RemoveChessPiece();        // Remove this piece from this cell
                    destinationCell.PlaceChessPiece(this); // Add this piece to dest cell
                    CurrentCell = destinationCell;
                    FirstMove   = false;
                    return(true);
                }
                return(false);
            }
        }
Ejemplo n.º 2
0
        public override bool Take(BoardCell destinationCell)
        {
            if (Player.Colour == destinationCell.ChessPiece.Player.Colour)
            {
                return(false);
            }                                                                                // Make sure we aren't trying to take ourselves.

            int cellsToMoveUp    = CurrentCell.YLoc - destinationCell.YLoc;
            int cellsToMoveDown  = destinationCell.YLoc - CurrentCell.YLoc;
            int cellsToMoveLeft  = CurrentCell.XLoc - destinationCell.XLoc;
            int cellsToMoveRight = destinationCell.XLoc - CurrentCell.XLoc;

            if (Player.Colour is Game.PlayerColour.White)
            {
                if ((cellsToMoveDown == 0 && (cellsToMoveLeft >= 0 || cellsToMoveRight >= 0) || // move left or right
                     (cellsToMoveLeft == 0 && cellsToMoveRight == 0 && cellsToMoveDown >= 0) || // move down
                     (cellsToMoveLeft == 0 && cellsToMoveRight == 0 && cellsToMoveUp >= 0)))   // move up
                {
                    //destinationCell.ChessPiece.Pb.Visible = false; // makes the PictureBox invisible
                    destinationCell.RemoveChessPiece();    // Remove the piece from the dest cell. This and the previous line should make the peice being took unselectable and unseeable.
                    CurrentCell.RemoveChessPiece();        // Remove this piece from this cell
                    destinationCell.PlaceChessPiece(this); // Add this piece to dest cell
                    CurrentCell = destinationCell;
                    //Place(CurrentCell);
                    //Pb.BackColor = CurrentCell.Button.BackColor;
                    return(true);
                }
                return(false);
            }
            else // Player is Black
            {
                if ((cellsToMoveUp == 0 && (cellsToMoveLeft >= 0 || cellsToMoveRight >= 0) || // move left or right
                     (cellsToMoveLeft == 0 && cellsToMoveRight == 0 && cellsToMoveDown >= 0) || // move down
                     (cellsToMoveLeft == 0 && cellsToMoveRight == 0 && cellsToMoveUp >= 0)))   // move up
                {
                    //destinationCell.ChessPiece.Pb.Visible = false; // makes the PictureBox invisible
                    destinationCell.RemoveChessPiece();    // Remove the piece from the dest cell. This and the previous line should make the peice being took unselectable and unseeable.
                    CurrentCell.RemoveChessPiece();        // Remove this piece from this cell
                    destinationCell.PlaceChessPiece(this); // Add this piece to dest cell
                    CurrentCell = destinationCell;
                    //Place(CurrentCell);
                    //Pb.BackColor = CurrentCell.Button.BackColor;
                    return(true);
                }
                return(false);
            }
        }
Ejemplo n.º 3
0
        public override bool Move(BoardCell destinationCell)
        {
            int cellsToMoveUp    = CurrentCell.YLoc - destinationCell.YLoc;
            int cellsToMoveDown  = destinationCell.YLoc - CurrentCell.YLoc;
            int cellsToMoveLeft  = CurrentCell.XLoc - destinationCell.XLoc;
            int cellsToMoveRight = destinationCell.XLoc - CurrentCell.XLoc;

            if (IsPathToDestObstructed(destinationCell))
            {
                return(false);
            }

            if (destinationCell.Occupied)
            {
                return(Take(destinationCell));
            }

            if (Player.Colour == Game.PlayerColour.White)
            {
                if (cellsToMoveUp == cellsToMoveLeft || cellsToMoveUp == cellsToMoveRight || (cellsToMoveUp == 1 && cellsToMoveLeft == 0 && cellsToMoveRight == 0) ||
                    cellsToMoveDown == cellsToMoveLeft || cellsToMoveDown == cellsToMoveRight || (cellsToMoveDown == 1 && cellsToMoveLeft == 0 && cellsToMoveRight == 0) ||
                    cellsToMoveLeft == cellsToMoveUp || cellsToMoveLeft == cellsToMoveDown || (cellsToMoveLeft == 1 && cellsToMoveUp == 0 && cellsToMoveDown == 0) ||
                    cellsToMoveRight == cellsToMoveUp || cellsToMoveRight == cellsToMoveDown || (cellsToMoveRight == 1 && cellsToMoveUp == 0 && cellsToMoveDown == 0))
                {
                    CurrentCell.RemoveChessPiece();        // Remove this piece from this cell
                    destinationCell.PlaceChessPiece(this); // Add this piece to dest cell
                    CurrentCell = destinationCell;
                    return(true);
                }
                return(false);
            }
            else // Player is black
            {
                if (cellsToMoveUp == cellsToMoveLeft || cellsToMoveUp == cellsToMoveRight || (cellsToMoveUp == 1 && cellsToMoveLeft == 0 && cellsToMoveRight == 0) ||
                    cellsToMoveDown == cellsToMoveLeft || cellsToMoveDown == cellsToMoveRight || (cellsToMoveDown == 1 && cellsToMoveLeft == 0 && cellsToMoveRight == 0) ||
                    cellsToMoveLeft == cellsToMoveUp || cellsToMoveLeft == cellsToMoveDown || (cellsToMoveLeft == 1 && cellsToMoveUp == 0 && cellsToMoveDown == 0) ||
                    cellsToMoveRight == cellsToMoveUp || cellsToMoveRight == cellsToMoveDown || (cellsToMoveRight == 1 && cellsToMoveUp == 0 && cellsToMoveDown == 0))
                {
                    CurrentCell.RemoveChessPiece();        // Remove this piece from this cell
                    destinationCell.PlaceChessPiece(this); // Add this piece to dest cell
                    CurrentCell = destinationCell;
                    return(true);
                }
                return(false);
            }
        }
Ejemplo n.º 4
0
        public override bool Take(BoardCell destinationCell)
        {
            if (Player.Colour == destinationCell.ChessPiece.Player.Colour)
            {
                return(false);
            }                                                                                // Make sure we aren't trying to take ourselves.

            int pixelsToMoveUp    = CurrentCell.YLoc - destinationCell.YLoc;
            int pixelsToMoveDown  = destinationCell.YLoc - CurrentCell.YLoc;
            int pixelsToMoveLeft  = CurrentCell.XLoc - destinationCell.XLoc;
            int pixelsToMoveRight = destinationCell.XLoc - CurrentCell.XLoc;

            if (Player.Colour is Game.PlayerColour.White)
            {
                if (pixelsToMoveDown == ChessBoard.CellSpace &&
                    (pixelsToMoveRight > 0 && pixelsToMoveRight <= ChessBoard.CellSpace ||
                     pixelsToMoveLeft > 0 && pixelsToMoveLeft <= ChessBoard.CellSpace))
                {
                    destinationCell.RemoveChessPiece();    // Remove the piece from the dest cell. This and the previous line should make the peice being took unselectable and unseeable.
                    CurrentCell.RemoveChessPiece();        // Remove this piece from this cell
                    destinationCell.PlaceChessPiece(this); // Add this piece to dest cell
                    CurrentCell = destinationCell;
                    return(true);
                }
                return(false);
            }
            else // Player is Black
            {
                if (pixelsToMoveUp == ChessBoard.CellSpace &&
                    (pixelsToMoveRight > 0 && pixelsToMoveRight <= ChessBoard.CellSpace ||
                     pixelsToMoveLeft > 0 && pixelsToMoveLeft <= ChessBoard.CellSpace))
                {
                    destinationCell.RemoveChessPiece();    // Remove the piece from the dest cell. This and the previous line should make the peice being took unselectable and unseeable.
                    CurrentCell.RemoveChessPiece();        // Remove this piece from this cell
                    destinationCell.PlaceChessPiece(this); // Add this piece to dest cell
                    CurrentCell = destinationCell;
                    return(true);
                }
                return(false);
            }
        }
Ejemplo n.º 5
0
        public override bool Take(BoardCell destinationCell)
        {
            int cellsToMoveUp    = CurrentCell.YLoc - destinationCell.YLoc;
            int cellsToMoveDown  = destinationCell.YLoc - CurrentCell.YLoc;
            int cellsToMoveLeft  = CurrentCell.XLoc - destinationCell.XLoc;
            int cellsToMoveRight = destinationCell.XLoc - CurrentCell.XLoc;

            if (Player.Colour == Game.PlayerColour.White)
            {
                if (cellsToMoveUp == 1 && (cellsToMoveRight <= 1 || cellsToMoveLeft <= 1) ||
                    cellsToMoveDown == 1 && (cellsToMoveRight <= 1 || cellsToMoveLeft <= 1) ||
                    cellsToMoveLeft == 1 && (cellsToMoveDown <= 1 || cellsToMoveUp <= 1) ||
                    cellsToMoveRight == 1 && (cellsToMoveDown <= 1 || cellsToMoveUp <= 1))
                {
                    CurrentCell.RemoveChessPiece();        // Remove this piece from this cell
                    destinationCell.PlaceChessPiece(this); // Add this piece to dest cell
                    CurrentCell = destinationCell;
                    return(true);
                }
                return(false);
            }
            else // Player is black
            {
                if (cellsToMoveUp == 1 && (cellsToMoveRight <= 1 || cellsToMoveLeft <= 1) ||
                    cellsToMoveDown == 1 && (cellsToMoveRight <= 1 || cellsToMoveLeft <= 1) ||
                    cellsToMoveLeft == 1 && (cellsToMoveDown <= 1 || cellsToMoveUp <= 1) ||
                    cellsToMoveRight == 1 && (cellsToMoveDown <= 1 || cellsToMoveUp <= 1))
                {
                    CurrentCell.RemoveChessPiece();        // Remove this piece from this cell
                    destinationCell.PlaceChessPiece(this); // Add this piece to dest cell
                    CurrentCell = destinationCell;
                    return(true);
                }
                return(false);
            }
        }