/// <summary>
        /// Processes all events related to mouse and keyboard.
        /// </summary>
        /// <param name="inputManager">InputManager instance.</param>
        public virtual void Input(InputManager inputManager)
        {
            if (!PromotionWindow.Active)
            {
                VisualBoard.Input(inputManager);
            }

            PromotionWindow.Input(inputManager);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="GameModeBase"/> class.
        /// </summary>
        /// <param name="consoleManager">The console manager instance</param>
        /// <param name="commandsManager">The commands manager instance</param>
        protected GameModeBase(ConsoleManager consoleManager, CommandsManager commandsManager)
        {
            ConsoleManager  = consoleManager;
            CommandsManager = commandsManager;

            PiecesProvider = new PiecesProvider();

            VisualBoard     = new VisualBoard(PiecesProvider);
            PromotionWindow = new PromotionWindow(PiecesProvider);

            SetCommandHandlers();
        }
Exemple #3
0
        /// <summary>
        /// The event handler for OnFieldSelection.
        /// </summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void Board_OnFieldSelection(object sender, FieldSelectedEventArgs e)
        {
            if (!_done && _currentColor == _playerColor && e.Piece != null && e.Piece.Color == _currentColor)
            {
                var enemyColor = ColorOperations.Invert(_currentColor);

                var movesForPiece = Bitboard.Moves
                                    .Where(p => p.From == e.Position && !Bitboard.Moves.Any(q => p.Piece == PieceType.King &&
                                                                                            q.Color == enemyColor && q.To == p.To))
                                    .Select(p => p.To)
                                    .ToList();

                VisualBoard.AddExternalSelections(movesForPiece);
            }
        }
        /// <summary>
        /// The event handler for OnFieldSelection.
        /// </summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void Board_OnFieldSelection(object sender, FieldSelectedEventArgs e)
        {
            if (e.Piece == null)
            {
                var fieldAttackers = VisualBoard.FriendlyBoard.GetFieldAttackers(e.Position);
                VisualBoard.AddExternalSelections(fieldAttackers);
            }
            else
            {
                var movesForPiece = Bitboard.Moves
                                    .Where(p => p.From == e.Position)
                                    .Select(p => p.To)
                                    .ToList();

                VisualBoard.AddExternalSelections(movesForPiece);
            }
        }
        /// <summary>
        /// Draws all fields attacked by pieces with the specified color.
        /// </summary>
        /// <param name="command">The Attacks command.</param>
        private void DrawAttacks(Command command)
        {
            var colorArgument = command.GetArgument <string>(0);

            List <Position> attacks;

            if (colorArgument == "all")
            {
                attacks = VisualBoard.FriendlyBoard.GetAttacks();
            }
            else
            {
                var colorTypeParseResult = Enum.TryParse(colorArgument, true, out Color colorType);
                if (!colorTypeParseResult)
                {
                    ConsoleManager.WriteLine($"$rInvalid color parameter ($R{colorArgument}$r)");
                    return;
                }

                attacks = VisualBoard.FriendlyBoard.GetAttacks(colorType);
            }

            VisualBoard.AddExternalSelections(attacks);
        }
 /// <summary>
 /// Loads the resources. Must be called before first use of any other class method.
 /// </summary>
 /// <param name="contentManager">Monogame content manager.</param>
 public virtual void LoadContent(ContentManager contentManager)
 {
     PiecesProvider.LoadContent(contentManager);
     VisualBoard.LoadContent(contentManager);
     PromotionWindow.LoadContent(contentManager);
 }
 /// <summary>
 /// Draws board and promotion window (optionally).
 /// </summary>
 /// <param name="spriteBatch">Monogame sprite batch.</param>
 public virtual void Draw(SpriteBatch spriteBatch)
 {
     VisualBoard.Draw(spriteBatch);
     PromotionWindow.Draw(spriteBatch);
 }
 /// <summary>
 /// Processes all logic related to the base game mode.
 /// </summary>
 public virtual void Logic()
 {
     VisualBoard.Logic();
     PromotionWindow.Logic();
 }