Пример #1
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>	Dispatches a command. </summary>
        ///
        /// <remarks>	Darrellp, 10/8/2011. </remarks>
        ///
        /// <param name="command">	The command to be dispatched. </param>
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        public void Dispatch(IRogueCommand command)
        {
            // Is the command null?
            if (command == null)
            {
                return;
            }

            // Can we handle it as a direction command?
            if (HandleMovementCommands(command))
            {
                return;
            }

            // Switch on the command type
            switch (command.Command)
            {
            case CommandType.NewLevel:
                _game.SetLevel((NewLevelCommand)command);
                break;

            case CommandType.MoveTo:
                MoveTo((MoveToCommand)command);
                break;
            }
        }
Пример #2
0
        internal void DispatchOnKey(Key key)
        {
            IRogueCommand command = null;

            if (Directions.ContainsKey(key))
            {
                bool shouldRun = Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift);
                command = new MovementCommand(Directions[key], shouldRun);
            }

            _mainWindow.MessageTextblock.Text = string.Empty;
            _game.EnqueueAndProcess(command);
        }
Пример #3
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>	Handle movement commands. </summary>
        ///
        /// <remarks>	Darrellp, 10/8/2011. </remarks>
        ///
        /// <param name="command">	The command to be dispatched. </param>
        ///
        /// <returns>	true if this was a movement command, false otherwise. </returns>
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        public virtual bool HandleMovementCommands(IRogueCommand command)
        {
            // Is it a direction command?
            if (Directions.ContainsKey(command.Command))
            {
                // Is it a stay put command?
                if (command.Command == CommandType.StayPut)
                {
                    // Let the monsters do their thing and...
                    _game.CurrentLevel.InvokeMonsterAI();

                    return(true);
                }

                // Get values from the command
                MapCoordinates offset      = Directions[command.Command];
                bool           run         = ((MovementCommand)command).Run;
                MapCoordinates newLocation = Map.Player.Location + offset;
                Creature       victim;

                // Are we running?
                if (run)
                {
                    // Locals
                    var proposedLocation = Map.Player.Location + offset;
                    var maybeBlocksUs    = proposedLocation + offset;

                    // If we're blocked before we start...
                    if (!Map.ValidRunningMove(proposedLocation))
                    {
                        // Nothing to do...just return true
                        return(true);
                    }

                    List <MapCoordinates> litAtStartOfRun = _game.Map.Fov.CurrentlySeen.ToList();

                    // While we're not blocked ahead
                    while (Map.ValidRunningMove(maybeBlocksUs))
                    {
                        // Move to the proposed location
                        MakePlayerMove(proposedLocation, run: true);

                        // And advance our two pointers along
                        proposedLocation = maybeBlocksUs;
                        maybeBlocksUs    = maybeBlocksUs + offset;
                    }

                    // Last move is made without running
                    // This is so the caller knows when to update his screen
                    MakePlayerMove(proposedLocation, run: false, litAtStartOfRun: litAtStartOfRun);
                }
                // Else if some unfortunate is in our way
                else if ((victim = Map.CreatureAt(newLocation)) != null)
                {
                    // Attack him
                    MakeAttack(Map.Player, victim);

                    // Monsters do their thing
                    _game.CurrentLevel.InvokeMonsterAI();
                }
                // Else if this is valid terrain
                else if (Map.IsWalkable(newLocation))
                {
                    // Move the player
                    MakePlayerMove(newLocation);
                }
                else
                {
                    Map.NotifyOfBlockage(Map.Player, newLocation);
                }
                return(true);
            }

            // Unhandled as a movement key
            return(false);
        }
Пример #4
0
 ////////////////////////////////////////////////////////////////////////////////////////////////////
 /// <summary>	Dispatches a command. </summary>
 ///
 /// <remarks>	Relegates this to the command dispatcher.  Darrellp, 10/8/2011. </remarks>
 ///
 /// <param name="command">	The command to be dispatched. </param>
 ////////////////////////////////////////////////////////////////////////////////////////////////////
 internal void Dispatch(IRogueCommand command)
 {
     _commandDispatcher.Dispatch(command);
 }
Пример #5
0
 ////////////////////////////////////////////////////////////////////////////////////////////////////
 /// <summary>	Enqueue a command and process the queue. </summary>
 ///
 /// <remarks>	Darrellp, 10/11/2011. </remarks>
 ///
 /// <param name="command">	The command to be enqueued. </param>
 ////////////////////////////////////////////////////////////////////////////////////////////////////
 public void EnqueueAndProcess(IRogueCommand command)
 {
     Enqueue(command);
     Process();
 }
Пример #6
0
 ////////////////////////////////////////////////////////////////////////////////////////////////////
 /// <summary>	Queues up a command to be processed in next processing round. </summary>
 ///
 /// <remarks>	Darrellp, 10/11/2011. </remarks>
 ///
 /// <param name="command">	The command to be enqueued. </param>
 ////////////////////////////////////////////////////////////////////////////////////////////////////
 public void Enqueue(IRogueCommand command)
 {
     _commandQueue.AddCommand(command);
 }
Пример #7
0
 internal void AddCommand(IRogueCommand command)
 {
     _commands.Enqueue(command);
 }