void Update() { if (Input.GetKey(KeyCode.UpArrow)) { moveUp = new UpCommand(this.transform, _speed); moveUp.Execute(); MoveGameManager.Instance.AddCommand(moveUp); } if (Input.GetKey(KeyCode.DownArrow)) { moveDown = new DownCommand(this.transform, _speed); moveDown.Execute(); MoveGameManager.Instance.AddCommand(moveDown); } if (Input.GetKey(KeyCode.LeftArrow)) { moveLeft = new LeftCommand(this.transform, _speed); moveLeft.Execute(); MoveGameManager.Instance.AddCommand(moveLeft); } if (Input.GetKey(KeyCode.RightArrow)) { moveRight = new RightCommand(this.transform, _speed); moveRight.Execute(); MoveGameManager.Instance.AddCommand(moveRight); } }
public Command CreateCommand(char commandChar, Engine engine) { Command command = null; switch (commandChar) { case 'V': command = new DownCommand(engine); break; case '^': command = new UpCommand(engine); break; case '<': command = new LeftCommand(engine); break; case '>': command = new RightCommand(engine); break; default: throw new ArgumentException("Invalid command!"); } return(command); }
// Update is called once per frame void Update() { if (Input.GetKey(KeyCode.UpArrow)) { ICommand command = new UpCommand(this.transform, this._speed); command.Execute(); CommandManager.Instance.AddCommand(command); } else if (Input.GetKey(KeyCode.DownArrow)) { ICommand command = new DownCommand(this.transform, this._speed); command.Execute(); CommandManager.Instance.AddCommand(command); } else if (Input.GetKey(KeyCode.RightArrow)) { ICommand command = new RightCommand(this.transform, this._speed); command.Execute(); CommandManager.Instance.AddCommand(command); } else if (Input.GetKey(KeyCode.LeftArrow)) { ICommand command = new LeftCommand(this.transform, this._speed); command.Execute(); CommandManager.Instance.AddCommand(command); } else if (Input.GetKeyDown(KeyCode.Space)) { CommandManager.Instance.Reverse(); } }
public void Down(int port) { var command = new DownCommand(); Wrapper.Run(command.Arguments(port)); PortState[port].Enabled = false; }
//public InteractionRequest<Notification> AddRequest { get; } = new InteractionRequest<Notification>(); //public InteractionRequest<Notification> EditRequest { get; } = new InteractionRequest<Notification>(); public MetadataImportSettingDialogViewModel(IDirectoryNameParserManager directoryNameParserManager) { DirectoryNameParserManager = directoryNameParserManager; DirectoryNameParsers = DirectoryNameParserManager .Items .ToReadOnlyReactiveCollection(x => new DirectoryNameParserViewModel(DirectoryNameParserManager, x)); UpCommand = SelectedParser .Select(x => x != null && DirectoryNameParserManager.Items.Count >= 2 && GetIndex(x.Model) > 0) .ToReactiveCommand(); UpCommand .Subscribe(() => Up()); DownCommand = SelectedParser .Select(x => x != null && DirectoryNameParserManager.Items.Count >= 2 && GetIndex(x.Model) < DirectoryNameParserManager.Items.Count - 1) .ToReactiveCommand(); DownCommand .Subscribe(() => Down()); AddCommand .Select(_ => new DirectoryNameParser()) .Subscribe(x => throw new NotImplementedException() //AddRequest.Raise(new Notification //{ // Title = Resources.EditMetadataImportSettingDialogTitle_Add, // Content = x //}) ); EditCommand = SelectedParser .Select(x => x != null) .ToReactiveCommand(); EditCommand .Select(_ => SelectedParser.Value.Model) .Subscribe(x => throw new NotImplementedException() //EditRequest.Raise(new Notification //{ // Title = Resources.EditMetadataImportSettingDialogTitle_Edit, // Content = x //}) ); RemoveCommand = SelectedParser .Select(x => x != null) .ToReactiveCommand(); RemoveCommand .Subscribe(() => Remove()); CloseCommand .Subscribe(dialog => { DirectoryNameParserManager.Save(); dialog.DialogResult = true; }); }
public CompositionMakeViewModel(GameInfo gameInfo, Window window) { this.gameInfo = gameInfo; this.window = window; VehicleNums = gameInfo.vehicles.ToDictionary(vehicle => vehicle, _ => 0); QuantUp = new UpCommand(this); QuantDown = new DownCommand(this); Make = new MakeCommand(this); }
public CompositionManageViewModel(GameInfo gameInfo, Window window) { this.gameInfo = gameInfo; this.window = window; Compositions = gameInfo.compositions; QuantUp = new UpCommand(this); QuantDown = new DownCommand(this); Buy = new BuyCommand(this); Sale = new SaleCommand(this); }
void Start() { ICommand up = new UpCommand(); ICommand down = new DownCommand(); ICommand left = new LeftCommand(); ICommand right = new RightCommand(); dict.Add(KeyCode.UpArrow, up); dict.Add(KeyCode.DownArrow, down); dict.Add(KeyCode.LeftArrow, left); dict.Add(KeyCode.RightArrow, right); }
void Start() { ICommand up = new UpCommand(); ICommand down = new DownCommand(); ICommand left = new LeftCommand(); ICommand right = new RightCommand(); dict.Add(KeyCode.W, up); dict.Add(KeyCode.S, down); dict.Add(KeyCode.A, left); dict.Add(KeyCode.D, right); }
private void OnDownInternal() { OnDown(); var handler = Down; if (handler != null) { handler(_button, EventArgs.Empty); } if (DownCommand != null && DownCommand.CanExecute(DownCommandParameter)) { DownCommand.Execute(DownCommandParameter); } }
/// <summary> /// revisa si el usuario está presionando alguna /// de las flechas de movimiento en el teclado, /// crea el comando correspondiente y lo envia /// a el personaje del jugador. /// </summary> private void CapturarComando() { // Se crea una referencia nula al commando a ejecutar MovementCommand newCommand = null; // Se crea una referencia a la direccion // que tendra el comando a crear para // enviarlo a la interfaz. Direccion direccion = Direccion.derecha; // Si el jugador presiona alguna tecla, // entonces se crea el comando a ejecutar if (Input.GetKeyDown(KeyCode.UpArrow)) { newCommand = new UpCommand(); direccion = Direccion.arriba; } else if (Input.GetKeyDown(KeyCode.DownArrow)) { newCommand = new DownCommand(); direccion = Direccion.abajo; } else if (Input.GetKeyDown(KeyCode.LeftArrow)) { newCommand = new LeftCommand(); direccion = Direccion.izquierda; } else if (Input.GetKeyDown(KeyCode.RightArrow)) { newCommand = new RightCommand(); // no es necesario modificar el valor de la variable "dirección". } // Si alguno de las flechas en el teclado // fue presionada, entonces se le envia // el comando al personaje del jugador. if (newCommand != null) { Tablero.Character.RegistrarComandos(newCommand); // Solo se agrega la flecha en la dirección del movimiento // del jugador cuando se recibe un comando de este. UIManag.AgregarFlechaUI(direccion); } }
public static void Main(string[] args) { // our application will need some reveiver object Television device = new Television(); // our application will need an invoker object, which // in turns relies on concrete command objects: ICommand on = new OnCommand(device); // command to switch device on ICommand off = new OffCommand(device); // command to switch device off ICommand up = new UpCommand(device); // command to turn volume up ICommand down = new DownCommand(device);// command to turn volume down // now we are ready to create our invoker object which // we should think of as some sort of application menu. RemoteControl menu = new RemoteControl(on, off, up, down); // client code is now able to access the invoker object menu.SwitchPowerOn(); menu.RaiseVolume(); menu.RaiseVolume(); menu.RaiseVolume(); menu.LowerVolume(); menu.SwitchPowerOff(); }
public void visit(DownCommand down) { down.Execute(); }
public CollectionViewModel(TProperty property, ViewModelFactory factory) : base(property) { Collection = property.Collection.ToReadOnlyReactiveCollection(x => { IPropertyViewModel vm = null; try { vm = factory.Create(x); } catch (Exception e) { OnErrorSubject.OnNext(e); return(null); } vm.OnChanged.Subscribe(y => OnChangedSubject.OnNext(Unit.Default)); vm.OnError.Subscribe(e => OnErrorSubject.OnNext(e)); return(vm); }); FormatedString = Property.Count.Select(x => $"Count = {x}") .ToReactiveProperty(mode: ReactivePropertyMode.RaiseLatestValueOnSubscribe); AddCommand.Subscribe(x => { try { Property.AddNewElement(); } catch (Exception e) { OnErrorSubject.OnNext(e); } OnChangedSubject.OnNext(Unit.Default); }); RemoveCommand.Subscribe(x => { try { Property.RemoveElementAt(x); } catch (Exception e) { OnErrorSubject.OnNext(e); } OnChangedSubject.OnNext(Unit.Default); }); EditCommand.Subscribe(x => ShowDetailSubject.OnNext(this)); UpCommand.Subscribe(x => { Property.Move(x - 1, x); SelectedIndex.Value = x - 1; }); DownCommand.Subscribe(x => { Property.Move(x + 1, x); SelectedIndex.Value = x; }); DuplicateCommand.Subscribe(x => { Property.Duplicate(x, x + 1); }); }
public static void InitializeControllersForGameplay(Game1 game, KeyboardController keyboard, GamepadController gamepad) { keyboard.ClearDictionary(); gamepad.ClearDictionary(); //Background sound ICommand mutecommand = new MuteCommand(Stage.sound); keyboard.Add((int)Keys.M, mutecommand); //Add the Reset command to the r ICommand resetcommand = new ResetCommand(); keyboard.Add((int)Keys.R, resetcommand); gamepad.Add((int)Buttons.Back, resetcommand); //Add the Exit Command to the controllers ICommand exitcommand = new ExitCommand(game); keyboard.Add((int)Keys.Q, exitcommand); gamepad.Add((int)Buttons.Start, exitcommand); //add the left command ICommand leftcommand = new LeftCommand(Stage.mario); keyboard.Add((int)Keys.A, leftcommand); keyboard.Add((int)Keys.Left, leftcommand); gamepad.Add((int)Buttons.DPadLeft, leftcommand); //add the right commmand ICommand rightcommand = new RightCommand(Stage.mario); keyboard.Add((int)Keys.D, rightcommand); keyboard.Add((int)Keys.Right, rightcommand); gamepad.Add((int)Buttons.DPadRight, rightcommand); //Add the srpint command ICommand sprintcommand = new SprintCommand(Stage.mario); keyboard.Add((int)Keys.LeftShift, sprintcommand); keyboard.Add((int)Keys.RightShift, sprintcommand); //add the down command ICommand downcommand = new DownCommand(Stage.mario); keyboard.Add((int)Keys.S, downcommand); keyboard.Add((int)Keys.Down, downcommand); gamepad.Add((int)Buttons.DPadDown, downcommand); //add the up command ICommand upcommand = new UpCommand(Stage.mario); keyboard.Add((int)Keys.W, upcommand); keyboard.Add((int)Keys.Up, upcommand); gamepad.Add((int)Buttons.DPadUp, upcommand); //add fireflower command ICommand firecommand = new FireMarioCommand(Stage.mario); keyboard.Add((int)Keys.I, firecommand); //add super command ICommand supercommand = new SuperCommand(Stage.mario); keyboard.Add((int)Keys.U, supercommand); //add normal mario command ICommand normalcommand = new NormalCommand(Stage.mario); keyboard.Add((int)Keys.Y, normalcommand); //add take damage command ICommand damagecommand = new DamageCommand(Stage.mario); keyboard.Add((int)Keys.O, damagecommand); //add star power command ICommand starcommand = new StarCommand(Stage.mario); keyboard.Add((int)Keys.L, starcommand); //add the fireball command with space ICommand fireballcommand = new MakeFireBall(Stage.mario); keyboard.Add((int)Keys.Space, fireballcommand); //add the Pause hud command with N ICommand pausehudcommand = new PauseCommand(); keyboard.Add((int)Keys.P, pausehudcommand); ICommand interact = new InteractCommand(); keyboard.Add((int)Keys.V, interact); gamepad.Add((int)Buttons.RightTrigger, interact); //add hold command E, no current mapping on gamepad ICommand holdcommand = new HoldingCommand(Stage.mario); keyboard.Add((int)Keys.E, holdcommand); /* * Add release commands. These are mainly for mario movement. */ ICommand rightR = new ReleaseRightCommand(Stage.mario); keyboard.AddRelease((int)Keys.D, rightR); keyboard.AddRelease((int)Keys.Right, rightR); ICommand leftR = new ReleaseLeftCommand(Stage.mario); keyboard.AddRelease((int)Keys.A, leftR); keyboard.AddRelease((int)Keys.Left, leftR); ICommand downR = new ReleaseDownCommand(Stage.mario); keyboard.AddRelease((int)Keys.S, downR); keyboard.AddRelease((int)Keys.Down, downR); ICommand upR = new ReleaseUpCommand(Stage.mario); keyboard.AddRelease((int)Keys.W, upR); keyboard.AddRelease((int)Keys.Up, upR); ICommand sprintR = new ReleaseSprintCommand(Stage.mario); keyboard.AddRelease((int)Keys.LeftShift, sprintR); keyboard.AddRelease((int)Keys.RightShift, sprintR); ICommand holdR = new ReleaseHoldingCommand(Stage.mario); keyboard.AddRelease((int)Keys.E, holdR); }
public void Update() { gamePadState = GamePad.GetState(PlayerIndex.One); ICommand command; ICommand idleCommand = new IdleMarioCommand(Game1.Instance); if (gamePadState.IsButtonDown(Buttons.A) || gamePadState.IsButtonDown(Buttons.B) || gamePadState.IsButtonDown(Buttons.DPadLeft) || gamePadState.IsButtonDown(Buttons.DPadRight) || gamePadState.IsButtonDown(Buttons.DPadUp) || gamePadState.IsButtonDown(Buttons.DPadDown) || gamePadState.ThumbSticks.Left.X > 0.5f || gamePadState.ThumbSticks.Left.X < -0.5f || gamePadState.ThumbSticks.Left.Y > 0.5f || gamePadState.ThumbSticks.Left.X < -0.5f || gamePadState.IsButtonDown(Buttons.Back) || gamePadState.IsButtonDown(Buttons.Start)) { if (gamePadState.IsButtonDown(Buttons.A)) { command = new UpCommand(Game1.Instance); command.Execute(); } if (gamePadState.IsButtonDown(Buttons.B)) { command = new FireBallCommand(Game1.Instance); command.Execute(); command = new SprintCommand(Game1.Instance); command.Execute(); } if (gamePadState.IsButtonDown(Buttons.DPadLeft)) { command = new LeftCommand(Game1.Instance); command.Execute(); } if (gamePadState.IsButtonDown(Buttons.DPadRight)) { command = new RightCommand(Game1.Instance); command.Execute(); } if (gamePadState.IsButtonDown(Buttons.DPadUp)) { command = new UpCommand(Game1.Instance); command.Execute(); } if (gamePadState.IsButtonDown(Buttons.DPadDown)) { command = new DownCommand(Game1.Instance); command.Execute(); } if (gamePadState.ThumbSticks.Left.X > 0.5f) { command = new RightCommand(Game1.Instance); command.Execute(); } if (gamePadState.ThumbSticks.Left.X < -0.5f) { command = new LeftCommand(Game1.Instance); command.Execute(); } if (gamePadState.ThumbSticks.Left.Y > 0.5f) { command = new UpCommand(Game1.Instance); command.Execute(); } if (gamePadState.ThumbSticks.Left.X < -0.5f) { command = new DownCommand(Game1.Instance); command.Execute(); } if (gamePadState.IsButtonDown(Buttons.Back)) { command = new ExitCommand(Game1.Instance); command.Execute(); } if (gamePadState.IsButtonDown(Buttons.Start)) { command = new SwitchControllerCommand(); command.Execute(); } if (!gamePadState.IsButtonDown(Buttons.DPadLeft) && !gamePadState.IsButtonDown(Buttons.DPadRight)) { command = new IdleMarioCommand(Game1.Instance); command.Execute(); } } else { idleCommand.Execute(); } }
public void flipDown() { DownCommand.execute(); }