protected void SetupRx() { var hasNextItems = this.WhenAnyValue(y => y.CurrentItemIndex, x => x.Items) .Select(x => x.Item2 != null && x.Item2.Length > 1 && x.Item1 < (x.Item2.Length - 1)); NextItemCommand = ReactiveCommand.Create( this.LoadCommand.CanExecuteObservable.CombineLatest( hasNextItems, (canLoad, hasNext) => canLoad && hasNext) .DistinctUntilChanged() .StartWith(false)); NextItemCommand.Subscribe(x => CurrentItemIndex += 1); var hasPreviousItems = this.WhenAnyValue(y => y.CurrentItemIndex, x => x.Items) .Select(x => x.Item2 != null && x.Item2.Length > 1 && x.Item1 > 0); PreviousItemCommand = ReactiveCommand.Create( this.LoadCommand.CanExecuteObservable.CombineLatest( hasPreviousItems, (canLoad, hasPrevious) => canLoad && hasPrevious) .DistinctUntilChanged() .StartWith(false)); PreviousItemCommand.Subscribe(x => CurrentItemIndex -= 1); }
public KeyboardController(GameManager game) { prevState = Keyboard.GetState(); manager = game; //setup commands ICommand Attack = new PlayerAttackCommand(game.getPlayer(), game); Move = new PlayerMoveCommand(game.getPlayer()); Idle = new PlayerIdleCommand(game.getPlayer()); ICommand Arrow = new PlayerArrowCommand(game.getPlayer(), game); ICommand Bomb = new PlayerBombCommand(game.getPlayer(), game); ICommand Boomerang = new PlayerBoomerangCommand(game.getPlayer(), game); ICommand Hurt = new PlayerHurtCommand(game.getPlayer(), game); ICommand Left = new PlayerChangeDirectionCommand(game.getPlayer(), game, 3); ICommand Up = new PlayerChangeDirectionCommand(game.getPlayer(), game, 0); ICommand Down = new PlayerChangeDirectionCommand(game.getPlayer(), game, 1); ICommand Right = new PlayerChangeDirectionCommand(game.getPlayer(), game, 2); ICommand quit = new QuitCommand(game); ICommand nextBlock = new CycleBocksCommand(game, 1); ICommand prevBlock = new CycleBocksCommand(game, -1); ICommand nextItem = new CycleItemCommand(game, 1); ICommand prevItem = new CycleItemCommand(game, -1); ICommand nextEnemy = new CycleEnemyCommand(game, 1); ICommand prevEnemy = new CycleEnemyCommand(game, -1); ICommand playing = new SetGameStateCommand(game, 0); ICommand inventorySelection = new SetGameStateCommand(game, 1); ICommand pause = new SetGameStateCommand(game, 2); ICommand lose = new SetGameStateCommand(game, 3); ICommand win = new SetGameStateCommand(game, 4); ICommand nextItemSelect = new NextItemCommand(game); ICommand prevItemSelect = new PreviousItemCommand(game); ICommand useSelectedItem = new UseSelectedItemCommand(game); //item selection kepMap ItemSelectionKeyMap = new Dictionary <Keys, ICommand>(); ItemSelectionKeyMap.Add(Keys.C, playing); ItemSelectionKeyMap.Add(Keys.A, prevItemSelect); ItemSelectionKeyMap.Add(Keys.Left, prevItemSelect); ItemSelectionKeyMap.Add(Keys.D, nextItemSelect); ItemSelectionKeyMap.Add(Keys.Right, nextItemSelect); //pause kepMap PauseKeyMap = new Dictionary <Keys, ICommand>(); PauseKeyMap.Add(Keys.C, playing); s2reset = new S2Reset(game); //KeyMap.Add(Keys.A, new PlayerAttackCommand(game.player)); PlayingKeyMap = new Dictionary <Keys, ICommand>(); PlayingKeyMap.Add(Keys.P, pause); PlayingKeyMap.Add(Keys.I, inventorySelection); PlayingKeyMap.Add(Keys.Z, Attack); PlayingKeyMap.Add(Keys.N, Attack); PlayingKeyMap.Add(Keys.X, useSelectedItem); PlayingKeyMap.Add(Keys.M, useSelectedItem); //KeyMap.Add(Keys.A, Move); PlayingKeyMap.Add(Keys.D1, Arrow); PlayingKeyMap.Add(Keys.D2, Bomb); PlayingKeyMap.Add(Keys.D3, Boomerang); PlayingKeyMap.Add(Keys.E, Hurt); PlayingKeyMap.Add(Keys.W, Up); PlayingKeyMap.Add(Keys.A, Left); PlayingKeyMap.Add(Keys.S, Down); PlayingKeyMap.Add(Keys.D, Right); PlayingKeyMap.Add(Keys.Up, Up); PlayingKeyMap.Add(Keys.Left, Left); PlayingKeyMap.Add(Keys.Down, Down); PlayingKeyMap.Add(Keys.Right, Right); //KeyMap.Add(Keys.Y, Idle); PlayingKeyMap.Add(Keys.Escape, quit); //PlayingKeyMap.Add(Keys.T, prevBlock); //PlayingKeyMap.Add(Keys.Y, nextBlock); //PlayingKeyMap.Add(Keys.U, prevItem); //PlayingKeyMap.Add(Keys.I, nextItem); //PlayingKeyMap.Add(Keys.O, prevEnemy); //PlayingKeyMap.Add(Keys.P, nextEnemy); PlayingKeyMap.Add(Keys.R, s2reset); PlayingKeyMap.Add(Keys.Q, quit); direcPriority = new Dictionary <Keys, int>(); direcPriority.Add(Keys.W, 0); direcPriority.Add(Keys.A, 0); direcPriority.Add(Keys.S, 0); direcPriority.Add(Keys.D, 0); direcPriority.Add(Keys.Up, 0); direcPriority.Add(Keys.Left, 0); direcPriority.Add(Keys.Down, 0); direcPriority.Add(Keys.Right, 0); moveKeys = new List <Keys>(); moveKeys.Add(Keys.W); moveKeys.Add(Keys.A); moveKeys.Add(Keys.S); moveKeys.Add(Keys.D); moveKeys.Add(Keys.Up); moveKeys.Add(Keys.Left); moveKeys.Add(Keys.Down); moveKeys.Add(Keys.Right); direcPressed = Keys.I; moveTotal = 0; }