Exemplo n.º 1
0
    /// <summary>
    /// Sets the state of the Player
    /// </summary>
    /// <param name="state">Which state to set</param>
    /// <exception cref="ArgumentOutOfRangeException"></exception>
    public void SetState(PlayerStates state)
    {
        PlayerBaseState playerState;

        switch (state)
        {
        case PlayerStates.Shoot:
            playerState = new ShootingState(this);
            break;

        case PlayerStates.Walking:
            playerState = new WalkingState(this);
            break;

        case PlayerStates.Talking:
            playerState = new TalkingState(this);
            break;

        case PlayerStates.Win:
            playerState = new WinState(this);
            break;

        default:
            throw new ArgumentOutOfRangeException(nameof(state), state, null);
        }

        _currentState?.ExitState();

        _currentState = playerState;

        _currentState.EnterState();
    }