Esempio n. 1
0
        public void ChangePosition(Piece piece, ChessPoint newPosition)
        {
            if (ReferenceEquals(piece, null))
            {
                throw new ArgumentNullException(nameof(piece));
            }

            if (ReferenceEquals(newPosition, null))
            {
                throw new ArgumentNullException(nameof(newPosition));
            }

            var oldCoordinates = new MappedCoordinates(piece.Coordinate);
            var newCoordinates = new MappedCoordinates(newPosition);

            if (!ReferenceEquals(_map[newCoordinates.X][newCoordinates.Y], null))
            {
                throw new BusyCellException("Can't change piece position: the cell with coodinates " +
                                            $"{newPosition.Letter}{newPosition.Number} ({newCoordinates.X}, {newCoordinates.Y}) is busy.");
            }

            _map[newCoordinates.X][newCoordinates.Y] = piece;
            _map[oldCoordinates.X][oldCoordinates.Y] = null;

            piece.Coordinate.Letter = newPosition.Letter;
            piece.Coordinate.Number = newPosition.Number;
        }
Esempio n. 2
0
 public MappedCoordinates(ChessPoint coordinate)
 {
     X = coordinate.Letter - 'a';
     Y = coordinate.Number - 1;
 }
Esempio n. 3
0
        public Piece GetPiece(ChessPoint cell)
        {
            var mapCoordinates = new MappedCoordinates(cell);

            return(_map[mapCoordinates.X][mapCoordinates.Y]);
        }