Ejemplo n.º 1
0
        public IPiece Create(ColourOfPiece colour, KindOfPiece kind, bool isFirstMovie = true)
        {
            ICheckStrategyFactory checkStrategyFactory = new CheckStrategyFactory();
            ICheckStrategy        checkStrategy        = checkStrategyFactory.Create(kind, isFirstMovie);

            return(new ChessPiece(colour, kind, checkStrategy));
        }
Ejemplo n.º 2
0
        private void CastlingDecoratorChanges(IPiece piece, Position position, ChessboardModel chessboard)
        {
            var strategyFacctory = new CheckStrategyFactory();

            switch (piece.Kind)
            {
            case KindOfPiece.Knight:
                piece.CheckStrategy = strategyFacctory.Create(piece.Kind, false);
                if (chessboard[0, position.Y].Piece?.Kind == KindOfPiece.Rook)
                {
                    chessboard[0, position.Y].Piece.CheckStrategy = strategyFacctory.Create(KindOfPiece.Rook, false);
                }
                if (chessboard[7, position.Y].Piece?.Kind == KindOfPiece.Rook)
                {
                    chessboard[7, position.Y].Piece.CheckStrategy = strategyFacctory.Create(KindOfPiece.Rook, false);
                }
                break;

            case KindOfPiece.Rook:
                piece.CheckStrategy = strategyFacctory.Create(piece.Kind, false);
                if (position.X == 0)
                {
                    chessboard[4, position.Y].Piece.CheckStrategy = strategyFacctory.CreateKingStrategyWithCastlingDecorator(TypeOfCastling.Short);
                }
                else if (position.X == 7)
                {
                    chessboard[4, position.Y].Piece.CheckStrategy = strategyFacctory.CreateKingStrategyWithCastlingDecorator(TypeOfCastling.Long);
                }
                break;

            default: throw new ApplicationException("unexpected argument");
            }
        }