Beispiel #1
0
        private async Task ExecuteCharacterCommand(IInputCommand currentCommand, string[] args)
        {
            if (this.Owner == null)
            {
                this.ResetOwner();
            }

            InputCommandResult commandResult = null;

            // Only enumerate over this collection once.
            bool hasCurrentlyExecutingCommands = this.currentlyExecutingCommands.Any();

            if (currentCommand == null && !hasCurrentlyExecutingCommands)
            {
                // No command was found and we have no state, so tell the user they've entered something invalid.
                commandResult = new InputCommandResult("Unknown Command.\r\n", true, null, this.Owner);
                this.CompleteProcessing(commandResult);
            }
            else if (currentCommand == null && hasCurrentlyExecutingCommands || hasCurrentlyExecutingCommands && this.currentlyExecutingCommands.Peek().ExclusiveCommand)
            {
                // If we have a command already being processed, we continue to process it
                currentCommand = this.currentlyExecutingCommands.Pop();
            }
            
            InputCommandResult result = await currentCommand.ExecuteAsync(this.Owner, args);
            this.CompleteProcessing(result);
        }
Beispiel #2
0
        public void Create_Synchronous_StronglyTypedCommandParameter_MutableState()
        {
            IInputCommand <int> command = Command.Create <int>(_ => { }, _ => false);

            Assert.IsType <RelayCommand <int> >(command);
            Assert.False(command.CanExecute(240));
        }
Beispiel #3
0
        public void Create_Synchronous_StronglyTypedCommandParameter_DefaultState()
        {
            IInputCommand <int> command = Command.Create <int>(_ => { });

            Assert.IsType <RelayCommand <int> >(command);
            Assert.True(command.CanExecute(240));
        }
 public InputCommandResult(bool isCommandCompleted, IInputCommand command, ICharacter executor)
 {
     this.Result = string.Empty;
     this.IsCommandCompleted = isCommandCompleted;
     this.CommandExecuted = command;
     this.Executor = executor;
 }
Beispiel #5
0
        public void Create_Synchronous_NoCommandParameter_DefaultState()
        {
            IInputCommand command = Command.Create(() => { });

            Assert.IsType <RelayCommand>(command);
            Assert.True(command.CanExecute());
        }
Beispiel #6
0
    public void RandomizeInput()
    {
        //TODO: Exercise 1.6 - Randomize inputmapping
        List <IInputCommand> commands = new List <IInputCommand>();

        commands.Add(up_command);
        commands.Add(down_command);
        commands.Add(left_command);
        commands.Add(right_command);
        commands.Add(jump_command);

        //Dictionary<int,string> controlName=new Dictionary<int, string>();
        //controlName.Add(0,"Up");
        //controlName.Add(1,"Down");
        //controlName.Add(2,"Left");
        //controlName.Add(3,"Right");
        //controlName.Add(4,"Jump");

        for (int i = 0; i < commands.Count; i++)
        {
            IInputCommand temp   = commands[i];
            int           rndNum = Random.Range(0, commands.Count - 1);
            commands[i]      = commands[rndNum];
            commands[rndNum] = temp;
        }

        up_command    = commands[0];
        down_command  = commands[1];
        left_command  = commands[2];
        right_command = commands[3];
        jump_command  = commands[4];

        m_inputMappingText.text = "W: ???\nS: ???\nA: ???\nD: ???\nSpace: ???";
    }
Beispiel #7
0
        private async Task ExecuteCharacterCommand(IInputCommand currentCommand, string[] args)
        {
            if (this.Owner == null)
            {
                this.ResetOwner();
            }

            InputCommandResult commandResult = null;

            // Only enumerate over this collection once.
            bool hasCurrentlyExecutingCommands = this.currentlyExecutingCommands.Any();

            if (currentCommand == null && !hasCurrentlyExecutingCommands)
            {
                // No command was found and we have no state, so tell the user they've entered something invalid.
                commandResult = new InputCommandResult("Unknown Command.\r\n", true, null, this.Owner);
                this.CompleteProcessing(commandResult);
            }
            else if (currentCommand == null && hasCurrentlyExecutingCommands || hasCurrentlyExecutingCommands && this.currentlyExecutingCommands.Peek().ExclusiveCommand)
            {
                // If we have a command already being processed, we continue to process it
                currentCommand = this.currentlyExecutingCommands.Pop();
            }

            InputCommandResult result = await currentCommand.ExecuteAsync(this.Owner, args);

            this.CompleteProcessing(result);
        }
Beispiel #8
0
        public void Create_Synchronous_NoCommandParameter_MutableState()
        {
            IInputCommand command = Command.Create(() => { }, () => false);

            Assert.IsType <RelayCommand>(command);
            Assert.False(command.CanExecute());
        }
 public InputCommandResult(bool isCommandCompleted, IInputCommand command, ICharacter executor)
 {
     this.Result             = string.Empty;
     this.IsCommandCompleted = isCommandCompleted;
     this.CommandExecuted    = command;
     this.Executor           = executor;
 }
Beispiel #10
0
        public Engine(IInitializer initializer, IInputCommand inputCommand)
        {
            this.graphics = new GraphicsDeviceManager(this);
            this.Content.RootDirectory = "Content";

            this.initializer  = initializer;
            this.inputCommand = inputCommand;
        }
Beispiel #11
0
        public InputHandler(Game game) : base(game)
        {
            _inputCommands = new Dictionary <Keys, IInputCommand>();

            _nullCommand = new InputNullCommand();

            _window = game.Window;
        }
        private string GetDefaultValueForInput(IInputCommand inputCommand, string promptText)
        {
            var defaultValue = inputCommand.GetDefaultValue(Processor.ActiveContext);

            if (!string.IsNullOrWhiteSpace(defaultValue))
            {
                return($"{promptText} [{defaultValue}]");
            }

            return(promptText);
        }
            public override bool Process(ICharacter owner, IInputCommand command, string[] args, out InputCommandResult result)
            {
                if (args.Length == 0)
                {
                    result = new InputCommandResult("Invalid password\r\n name: ", false, command, owner);
                    return(false);
                }

                result = new InputCommandResult("Login Successful\r\n", this.GetNextProcessor() != null, command, owner);
                return(true);
            }
Beispiel #14
0
    void Awake()
    {
        // creating the commands objects
        up_command    = new RunUp_Command();
        down_command  = new RunBack_Command();
        left_command  = new RotateLeft_Command();
        right_command = new RotateRight_Command();
        space_command = new Shoot_Command();

        _boolCanMove = false;
    }
Beispiel #15
0
 public static bool TryExecute <T>(this IInputCommand <T> command, T parameter)
 {
     if (command.CanExecute(parameter))
     {
         command.Execute(parameter);
         return(true);
     }
     else
     {
         return(false);
     }
 }
Beispiel #16
0
 public static bool TryExecute(this IInputCommand command)
 {
     if (command.CanExecute())
     {
         command.Execute();
         return(true);
     }
     else
     {
         return(false);
     }
 }
            public override bool Process(ICharacter owner, IInputCommand command, string[] args, out InputCommandResult result)
            {
                if (args.Length == 0 || string.IsNullOrWhiteSpace(args[0]))
                {
                    result = new InputCommandResult("You must enter a character name.", false, command, owner);
                    return(false);
                }

                this.notificationManager.Publish(new InformationMessage("Please enter your character's password: ", owner));
                result = new InputCommandResult(false, command, owner);
                return(true);
            }
Beispiel #18
0
        public Task ProcessCommandForCharacter(string command, string[] args)
        {
            IInputCommand currentCommand = CommandFactory.CreateCommandFromAlias(command);

            string[] correctedArguments = null;
            if (this.currentlyExecutingCommands.Any())
            {
                correctedArguments = Enumerable.Concat(new string[] { command, }, args).ToArray();
            }

            return(this.ProcessCommandForCharacter(currentCommand, correctedArguments));
        }
Beispiel #19
0
    private void Awake()
    {
        m_pm = FindObjectOfType <PlayerMotor>();
        //TODO: Exercise 1.4 - Assign concrete Commands to the instancevariables
        up_command    = new MoveUp_Command();
        down_command  = new MoveDown_Command();
        left_command  = new MoveLeft_Command();
        right_command = new MoveRight_Command();
        jump_command  = new Jump_Command();

        for (int i = 0; i < 5; i++)
        {
            controls.Add(i);
        }
    }
        private string GetCommandOptionsForInput(IInputCommand inputCommand, string promptText)
        {
            ICommand commandWithName = inputCommand;

            while (commandWithName != null && string.IsNullOrWhiteSpace(commandWithName.Name))
            {
                if (!string.IsNullOrWhiteSpace(commandWithName.Name))
                {
                    break;
                }

                commandWithName = commandWithName.Parent;
            }

            return
                ($"{promptText}: {commandWithName?.Name ?? string.Empty} ({inputCommand.GetPromptText(Processor.ActiveContext)})");
        }
Beispiel #21
0
 public abstract bool Process(ICharacter owner, IInputCommand command, string[] args, out InputCommandResult result);
Beispiel #22
0
 public abstract bool Process(ICharacter owner, IInputCommand command, string[] args, out InputCommandResult result);
Beispiel #23
0
 public void Register(T key, Func <T, bool> handler, IInputCommand command)
 {
     _commandMapper.Map(key, handler, command);
 }
Beispiel #24
0
 public void Register(InputEntry <T> entry, IInputCommand command)
 {
     _commandMapper.Map(entry, command);
 }
Beispiel #25
0
 void IEcsAutoReset.Reset()
 {
     ReturnInput  = false;
     InputCommand = null;
     SkipTurn     = false;
 }
Beispiel #26
0
 public void PushCommand(IInputCommand cmd)
 {
     synchronization.Add((own, input) => own.observer.PushCommand(input), cmd);
 }
 public override bool Process(ICharacter owner, IInputCommand command, string[] args, out InputCommandResult result)
 {
     this.notificationCenter.Publish(new InformationMessage("Please enter your character name: ", owner));
     result = new InputCommandResult(false, command, owner);
     return true;
 }
Beispiel #28
0
 public InputCommandAlreadyRegisteredException(IInputCommand inputCommand)
 {
     InputCommand = inputCommand;
 }
 public override bool Process(ICharacter owner, IInputCommand command, string[] args, out InputCommandResult result)
 {
     this.notificationCenter.Publish(new InformationMessage("Please enter your character name: ", owner));
     result = new InputCommandResult(false, command, owner);
     return(true);
 }
Beispiel #30
0
 public Task ProcessCommandForCharacter(IInputCommand command, string[] args)
 {
     return(this.ExecuteCharacterCommand(command, args));
 }
Beispiel #31
0
 public InputHandlerOnCommandAdd(InputHandler inputHandler, Keys key, IInputCommand inputCommand)
 {
     InputHandler = inputHandler;
     Key          = key;
     InputCommand = inputCommand;
 }
            public override bool Process(ICharacter owner, IInputCommand command, string[] args, out InputCommandResult result)
            {
                if (args.Length == 0)
                {
                    result = new InputCommandResult("Invalid password\r\n name: ", false, command, owner);
                    return false;
                }

                result = new InputCommandResult("Login Successful\r\n", this.GetNextProcessor() != null, command, owner);
                return true;
            }
Beispiel #33
0
        public InputCommandSample(Microsoft.Xna.Framework.Game game)
            : base(game)
        {
            GraphicsScreen.ClearBackground = true;

            _position = new Vector2F(600, 300);
            _color    = new Color((Vector3)RandomHelper.Random.NextVector3F(0, 1));

            // Create a command which detect presses of gamepad <A> or keyboard <Space>.
            _commandChangeColor = new ConfigurableInputCommand("ChangeColor")
            {
                Description        = "Change color.",
                LogicalPlayerIndex = LogicalPlayerIndex.One,
                PrimaryMapping     = new InputMapping
                {
                    PositiveButton = Buttons.A,
                    PressType      = PressType.Press,
                },
                SecondaryMapping = new InputMapping
                {
                    PositiveKey = Keys.Space,
                    PressType   = PressType.Press,
                },
            };

            // Create a command which uses the left stick or <A> and <D> to generate
            // value for horizontal movement..
            _commandMoveHorizontal = new ConfigurableInputCommand("MoveHorizontal")
            {
                Description        = "Move horizontally.",
                LogicalPlayerIndex = LogicalPlayerIndex.One,
                PrimaryMapping     = new InputMapping
                {
                    Axis = DeviceAxis.GamePadStickLeftX,
                },
                SecondaryMapping = new InputMapping
                {
                    PositiveDescription = "Move left.",
                    NegativeDescription = "Move right.",
                    PositiveKey         = Keys.D,
                    NegativeKey         = Keys.A,
                },
                Sensitivity = 0.5f, // Use quadratic response curve for thumb stick.
            };

            // Create a command which uses the left stick or <W> and <S> to generate
            // value for vertical movement.
            _commandMoveVertical = new ConfigurableInputCommand("MoveVertical")
            {
                Description        = "Move vertically.",
                LogicalPlayerIndex = LogicalPlayerIndex.One,
                PrimaryMapping     = new InputMapping
                {
                    Axis = DeviceAxis.GamePadStickLeftY,
                },
                SecondaryMapping = new InputMapping
                {
                    PositiveDescription = "Move up",
                    NegativeDescription = "Move down",
                    PositiveKey         = Keys.W,
                    NegativeKey         = Keys.S,
                },
                Sensitivity = 0.5f, // Use quadratic response curve for thumb stick.
            };

            InputService.Commands.Add(_commandChangeColor);
            InputService.Commands.Add(_commandMoveHorizontal);
            InputService.Commands.Add(_commandMoveVertical);
        }
Beispiel #34
0
 private void SetInputs()
 {
     _leftCommand  = new LeftCommand();
     _rightCommand = new RightCommand();
     _jumpCommand  = new JumpCommand();
 }
Beispiel #35
0
 public void PushCommand(IInputCommand cmd)
 {
     currentSnapshot.AddEvent(cmd);
 }
            public override bool Process(ICharacter owner, IInputCommand command, string[] args, out InputCommandResult result)
            {
                if (args.Length == 0 || string.IsNullOrWhiteSpace(args[0]))
                {
                    result = new InputCommandResult("You must enter a character name.", false, command, owner);
                    return false;
                }

                this.notificationManager.Publish(new InformationMessage("Please enter your character's password: ", owner));
                result = new InputCommandResult(false, command, owner);
                return true;
            }
Beispiel #37
0
    public InputCommandSample(Microsoft.Xna.Framework.Game game)
      : base(game)
    {
      GraphicsScreen.ClearBackground = true;

      _position = new Vector2F(600, 300);
      _color = new Color((Vector3)RandomHelper.Random.NextVector3F(0, 1));

      // Create a command which detect presses of gamepad <A> or keyboard <Space>.
      _commandChangeColor = new ConfigurableInputCommand("ChangeColor")
      {
        Description = "Change color.",
        LogicalPlayerIndex = LogicalPlayerIndex.One,
        PrimaryMapping = new InputMapping
        {
          PositiveButton = Buttons.A,
          PressType = PressType.Press,
        },
        SecondaryMapping = new InputMapping
        {
          PositiveKey = Keys.Space,
          PressType = PressType.Press,
        },
      };

      // Create a command which uses the left stick or <A> and <D> to generate 
      // value for horizontal movement..
      _commandMoveHorizontal = new ConfigurableInputCommand("MoveHorizontal")
      {
        Description = "Move horizontally.",
        LogicalPlayerIndex = LogicalPlayerIndex.One,
        PrimaryMapping = new InputMapping
        {
          Axis = DeviceAxis.GamePadStickLeftX,
        },
        SecondaryMapping = new InputMapping
        {
          PositiveDescription = "Move left.",
          NegativeDescription = "Move right.",
          PositiveKey = Keys.D,
          NegativeKey = Keys.A,
        },
        Sensitivity = 0.5f,   // Use quadratic response curve for thumb stick.
      };

      // Create a command which uses the left stick or <W> and <S> to generate 
      // value for vertical movement.
      _commandMoveVertical = new ConfigurableInputCommand("MoveVertical")
      {
        Description = "Move vertically.",
        LogicalPlayerIndex = LogicalPlayerIndex.One,
        PrimaryMapping = new InputMapping
        {
          Axis = DeviceAxis.GamePadStickLeftY,
        },
        SecondaryMapping = new InputMapping
        {
          PositiveDescription = "Move up",
          NegativeDescription = "Move down",
          PositiveKey = Keys.W,
          NegativeKey = Keys.S,
        },
        Sensitivity = 0.5f,   // Use quadratic response curve for thumb stick.
      };

      InputService.Commands.Add(_commandChangeColor);
      InputService.Commands.Add(_commandMoveHorizontal);
      InputService.Commands.Add(_commandMoveVertical);
    }
Beispiel #38
0
 public Task ProcessCommandForCharacter(IInputCommand command, string[] args)
 {
     return this.ExecuteCharacterCommand(command, args);
 }