Esempio n. 1
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 == 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);
            }
        }
Esempio n. 2
0
        public List <BoardCell> CellsInPath(BoardCell start, BoardCell end)
        {
            List <BoardCell> cellsInPath = new List <BoardCell>();
            int cellsToMoveUp            = start.YLoc - end.YLoc;
            int cellsToMoveDown          = end.YLoc - start.YLoc;
            int cellsToMoveLeft          = start.XLoc - end.XLoc;
            int cellsToMoveRight         = end.XLoc - start.XLoc;


            if (start != BoardCells[start.XLoc][start.YLoc])
            {
                Logger.Error("Cannot find the start position");
            }

            // straight up
            if (cellsToMoveUp > 0 && cellsToMoveLeft == 0 && cellsToMoveRight == 0)
            {
                for (int i = 1; i <= cellsToMoveUp; i++)
                {
                    cellsInPath.Add(BoardCells[start.XLoc][start.YLoc - i]);
                }
            }

            // straight down
            else if (cellsToMoveDown > 0 && cellsToMoveLeft == 0 && cellsToMoveRight == 0)
            {
                for (int i = 1; i <= cellsToMoveDown; i++)
                {
                    cellsInPath.Add(BoardCells[start.XLoc][start.YLoc + i]);
                }
            }
            // straight left
            else if (cellsToMoveLeft > 0 && cellsToMoveUp == 0 && cellsToMoveDown == 0)
            {
                for (int i = 1; i <= cellsToMoveLeft; i++)
                {
                    cellsInPath.Add(BoardCells[start.XLoc - i][start.YLoc]);
                }
            }

            // straight right
            else if (cellsToMoveRight > 0 && cellsToMoveUp == 0 && cellsToMoveDown == 0)
            {
                for (int i = 1; i <= cellsToMoveLeft; i++)
                {
                    cellsInPath.Add(BoardCells[start.XLoc + i][start.YLoc]);
                }
            }
            // diagonal up left
            else if (cellsToMoveUp > 0 && cellsToMoveLeft > 0 && cellsToMoveLeft == cellsToMoveUp)
            {
                for (int i = 1; i <= cellsToMoveUp; i++)
                {
                    cellsInPath.Add(BoardCells[start.XLoc - i][start.YLoc - i]);
                }
            }
            // diagonal up right
            else if (cellsToMoveUp > 0 && cellsToMoveRight > 0 && cellsToMoveRight == cellsToMoveUp)
            {
                for (int i = 1; i <= cellsToMoveUp; i++)
                {
                    cellsInPath.Add(BoardCells[start.XLoc + i][start.YLoc - i]);
                }
            }
            // diagonal down left
            else if (cellsToMoveDown > 0 && cellsToMoveLeft > 0 && cellsToMoveLeft == cellsToMoveDown)
            {
                for (int i = 1; i <= cellsToMoveDown; i++)
                {
                    cellsInPath.Add(BoardCells[start.XLoc - i][start.YLoc + i]);
                }
            }
            // diagonal down right
            else if (cellsToMoveDown > 0 && cellsToMoveLeft > 0 && cellsToMoveLeft == cellsToMoveDown)
            {
                for (int i = 1; i <= cellsToMoveDown; i++)
                {
                    cellsInPath.Add(BoardCells[start.XLoc + i][start.YLoc - i]);
                }
            }

            return(cellsInPath);
        }
Esempio n. 3
0
 public abstract bool Take(BoardCell destinationCell);