// 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();
     }
 }
        private void OnUpInternal()
        {
            OnUp();

            var handler = Up;

            if (handler != null)
            {
                handler(_button, EventArgs.Empty);
            }

            if (UpCommand != null &&
                UpCommand.CanExecute(UpCommandParameter))
            {
                UpCommand.Execute(UpCommandParameter);
            }
        }
        public void Update()
        {
            ICommand command = null;

            state = Keyboard.GetState();
            if ((state.IsKeyUp(Keys.Down) && state.IsKeyUp(Keys.S)) && (Mario.Instance.MovementState.MovementCode.Equals("RCRH") || Mario.Instance.MovementState.MovementCode.Equals("LCRH")))
            {
                command = new UpCommand();
                command.Execute();
            }

            foreach (Keys key in state.GetPressedKeys())
            {
                commandDictionary.TryGetValue(key.ToString(), out command);
                if (command != null)
                {
                    command.Execute();
                }
            }
        }
Beispiel #4
0
        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();
            }
        }
Beispiel #5
0
 public void visit(UpCommand up)
 {
     up.Execute();
 }