Exemplo n.º 1
0
    void Update()
    {
        if (_boolCanMove)
        {
            if (Input.GetKey(KeyCode.UpArrow))
            {
                up_command.Execute(plObject);
            }
            else if (Input.GetKey(KeyCode.DownArrow))
            {
                down_command.Execute(plObject);
            }

            if (Input.GetKey(KeyCode.RightArrow))
            {
                right_command.Execute(plObject);
            }
            else if (Input.GetKey(KeyCode.LeftArrow))
            {
                left_command.Execute(plObject);
            }

            if (Input.GetKey(KeyCode.Space))
            {
                if (Time.frameCount % _flShootRate == 0)
                {
                    space_command.Execute(plObject);
                }
            }
        }
    }
Exemplo n.º 2
0
 public static bool TryExecute(this IInputCommand command)
 {
     if (command.CanExecute())
     {
         command.Execute();
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 3
0
 public static bool TryExecute <T>(this IInputCommand <T> command, T parameter)
 {
     if (command.CanExecute(parameter))
     {
         command.Execute(parameter);
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 4
0
 private void Update()
 {
     if (Input.GetKeyDown(KeyCode.LeftArrow))
     {
         _leftCommand.Execute(_playerMoving);
     }
     else if (Input.GetKeyDown(KeyCode.RightArrow))
     {
         _rightCommand.Execute(_playerMoving);
     }
     else if (Input.GetKeyDown(KeyCode.Space))
     {
         _jumpCommand.Execute(_playerMoving);
     }
 }
Exemplo n.º 5
0
 void Update()
 {
     //TODO: Exercise 1.5 - Call the Execute-Method of each Command if the corresponding button was pressed.
     if (Input.GetKeyDown(KeyCode.W))
     {
         up_command.Execute(m_pm);
     }
     else if (Input.GetKeyDown(KeyCode.S))
     {
         down_command.Execute(m_pm);
     }
     else if (Input.GetKeyDown(KeyCode.A))
     {
         left_command.Execute(m_pm);
     }
     else if (Input.GetKeyDown(KeyCode.D))
     {
         right_command.Execute(m_pm);
     }
     else if (Input.GetKeyDown(KeyCode.Space))
     {
         jump_command.Execute(m_pm);
     }
 }