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); }
public void Create_Synchronous_StronglyTypedCommandParameter_MutableState() { IInputCommand <int> command = Command.Create <int>(_ => { }, _ => false); Assert.IsType <RelayCommand <int> >(command); Assert.False(command.CanExecute(240)); }
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; }
public void Create_Synchronous_NoCommandParameter_DefaultState() { IInputCommand command = Command.Create(() => { }); Assert.IsType <RelayCommand>(command); Assert.True(command.CanExecute()); }
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: ???"; }
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); }
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; }
public Engine(IInitializer initializer, IInputCommand inputCommand) { this.graphics = new GraphicsDeviceManager(this); this.Content.RootDirectory = "Content"; this.initializer = initializer; this.inputCommand = inputCommand; }
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); }
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; }
public static bool TryExecute <T>(this IInputCommand <T> command, T parameter) { if (command.CanExecute(parameter)) { command.Execute(parameter); return(true); } else { return(false); } }
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); }
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)); }
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)})"); }
public abstract bool Process(ICharacter owner, IInputCommand command, string[] args, out InputCommandResult result);
public abstract bool Process(ICharacter owner, IInputCommand command, string[] args, out InputCommandResult result);
public void Register(T key, Func <T, bool> handler, IInputCommand command) { _commandMapper.Map(key, handler, command); }
public void Register(InputEntry <T> entry, IInputCommand command) { _commandMapper.Map(entry, command); }
void IEcsAutoReset.Reset() { ReturnInput = false; InputCommand = null; SkipTurn = false; }
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; }
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); }
public Task ProcessCommandForCharacter(IInputCommand command, string[] args) { return(this.ExecuteCharacterCommand(command, args)); }
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; }
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); }
private void SetInputs() { _leftCommand = new LeftCommand(); _rightCommand = new RightCommand(); _jumpCommand = new JumpCommand(); }
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; }
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); }
public Task ProcessCommandForCharacter(IInputCommand command, string[] args) { return this.ExecuteCharacterCommand(command, args); }