/// <summary> /// Initlaizes Chess Piece /// </summary> /// <param name="chessBoard">Chess board holding the piece</param> /// <param name="direction">Direction towards which chess piece can move.</param> /// <param name="color">Color of chess piece</param> /// <exception cref="ArgumentNullException">chessBoard or direction</exception> protected ChessPiece(ChessBoard chessBoard, Direction direction, PieceColor color) { ChessBoard = chessBoard ?? throw new ArgumentNullException(nameof(chessBoard)); CurrentDirection = direction ?? throw new ArgumentNullException(nameof(direction)); Color = color; parentCell = null; IsCaptured = false; }
protected bool TryMoveChessPiece(Position newPosition) { if (!ChessBoard.IsLegalBoardPosition(newPosition)) { return(false); } IChessBoardCell cell = ChessBoard.Cells[newPosition.XCoordinate, newPosition.YCoordinate]; if (!cell.IsEmpty) { if (cell.ContainingChessPiece.Color == Color) { return(false); } cell.ContainingChessPiece.Capture(); } parentCell.RemoveChessPiece(); cell.PlaceChessPiece(this); return(true); }
/// <see cref="IChessPiece.SetParent"/> public void SetParent(IChessBoardCell cell) { parentCell = cell; }