Beispiel #1
0
    public void ChangeGameState(BaseGameState newState, bool pushPreviousState = false)
    {
        // destroy or push old state
        if (CurrentState != null)
        {
            CurrentState.OnExit -= OnExit;

            if (pushPreviousState)
            {
                _stateStack.Push(CurrentState);
            }
            else
            {
                CurrentState.Dispose();
            }
        }

        // set new state
        CurrentState = newState;

        Debug.Log("Changed state to " + CurrentState.GameState.ToString());

        CurrentState.OnExit += OnExit;
        CurrentState.EnterState();
    }
Beispiel #2
0
    public void changeStage(GameStage stage)
    {
        if (_curGameStage == stage)
        {
            return;
        }

        _curGameStage = stage;

        _curState.leaveState();

        switch (stage)
        {
        case GameStage.MOVE:
            _curState = _moveGameState;
            break;

        case GameStage.NOR:
            _curState = _norGameState;
            Debug.Log("stage change check");
            checkDel();
            break;

        default:
            _curState = _norGameState;
            break;
        }

        _curState.enterState();
    }
Beispiel #3
0
    public void RestorePreviousState(GameStates state = GameStates.None)
    {
        if (_stateStack.Count == 0)
        {
            throw new Exception("No previous states available");
        }

        // set target state to the previous state if none specified
        if (state == GameStates.None)
        {
            state = (_stateStack.Peek() as BaseGameState).GameState;
        }

        while (_stateStack.Count > 0 && CurrentState.GameState != state)
        {
            CurrentState.OnExit -= OnExit;
            CurrentState.Dispose();

            CurrentState = (BaseGameState)_stateStack.Pop();
        }

        if (CurrentState == null)
        {
            throw new Exception("Previous state not found: " + state.ToString());
        }

        Debug.Log("Restored state to " + CurrentState.GameState.ToString());

        CurrentState.OnExit += OnExit;
        CurrentState.EnterState();
    }
Beispiel #4
0
        public bool CheckCurrentState(State stateId)
        {
            BaseGameState state = null;

            _gameStates.TryGetValue(stateId, out state);
            return(_currentState == state);
        }
Beispiel #5
0
        public StateManager(MainGameState parent)
        {
            game = parent;

            mainMenuState = new MainMenuState(this);
            playingState  = new PlayingState(this);
            endGameState  = new EndGameState(this);
            currentState  = mainMenuState;
        }
Beispiel #6
0
        public BaseGameState GetState(GameStateController stateController, GameContext gameData)
        {
            if (_cashedState is null)
            {
                _cashedState = new GameplayState(stateController, gameData);
            }

            return(_cashedState);
        }
        public MainGame(int width, int height, BaseGameState firstGameState)
        {
            Content.RootDirectory = "Content";
            graphics = new GraphicsDeviceManager(this);

            _firstGameState                = firstGameState;
            _DesignedResolutionWidth       = width;
            _DesignedResolutionHeight      = height;
            _designedResolutionAspectRatio = width / (float)height;
        }
Beispiel #8
0
 // Update is called once per frame
 void Update()
 {
     curState.Execute();
     if (!curState.CheckIsAlive())
     {
         curState.Exit();
         curState = GetNextState();
         curState.Enter();
     }
     RefreshUI();
 }
Beispiel #9
0
        private void ChangeState(Type typeOfState)
        {
            var state = (BaseGameState)Activator.CreateInstance(typeOfState);

            state.OnStateChange -= CurrentGameState_OnStateChange;
            state.OnStateChange += CurrentGameState_OnStateChange;

            state.LoadContent(Content);

            _currentGameState = state;
        }
Beispiel #10
0
        public ExtractionGame()
        {
            HeroCollection.Load();

            Log.Info("Game Started");

            if (IsServer)
            {
                extractionHud    = new ExtractionHud();
                currentGameState = new BaseGameState();
            }
        }
    void OnLeaveState(object p1, object p2)
    {
        Type t = (Type)p1;

        Debug.Log("OnLeaveState" + t.Name + ", will = " + _willStateType.Name);
        if (_nowState.GetType() == t)
        {
            _nowState = GetState(_willStateType);
            _nowState.Enter(_willStateParameter);
            _willStateType = null;
        }
    }
Beispiel #12
0
    private void OnExitState(BaseGameState state)
    {
        switch (state.GameState)
        {
        case GameStates.MapEnter:
            _states.ChangeGameState(new MapWalkState());

            break;

        default:
            throw new Exception("Game state not found: " + state.GameState.ToString());
        }
    }
        public MainGame(int width, int height, BaseGameState firstGameState, bool debugMode)
        {
            Content.RootDirectory = "Content";
            _graphics             = new GraphicsDeviceManager(this);

            _firstGameState                = firstGameState;
            _DesignedResolutionWidth       = width;
            _DesignedResolutionHeight      = height;
            _designedResolutionAspectRatio = width / (float)height;

            var debug = new Debug(debugMode);

            Debug.Instance = debug;
        }
Beispiel #14
0
 public void ChangePrevState()
 {
     if (savePrevState != null && curState.ID == savePrevState.ID)
     {
         return;
     }
     if (curState != null)
     {
         curState.Leave();
     }
     curState = savePrevState;
     curState.Enter();
     prevState = curState;
 }
        public MainGame(int width, int height, BaseGameState firstGameState)
        {
            Content.RootDirectory = "Content";
            graphics = new GraphicsDeviceManager(this)
            {
                PreferredBackBufferWidth  = width,
                PreferredBackBufferHeight = height,
                IsFullScreen = false
            };

            _firstGameState                = firstGameState;
            _DesignedResolutionWidth       = width;
            _DesignedResolutionHeight      = height;
            _designedResolutionAspectRatio = width / (float)height;
        }
    // trocando o estado
    public void SwitchState(string newState)
    {
        BaseGameState state = FindState(newState);

        if (state == null)
        {
            Debug.LogError("Nao foi encontrado um estado com o nome " + newState);
            return;
        }

        stateStack[stateStack.Count - 1].Exit(state);
        state.Enter(stateStack[stateStack.Count - 1]);
        stateStack.RemoveAt(stateStack.Count - 1);
        stateStack.Add(state);
    }
Beispiel #17
0
    public BaseGameState savePrevState; //上一个状态

    public void ChangeState(BaseGameState newState)
    {
        if (curState != null && curState.ID == newState.ID)
        {
            return;
        }
        if (prevState != null)
        {
            savePrevState = prevState;
            prevState.Leave();
        }
        curState = newState;
        curState.Enter();
        prevState = curState;
    }
Beispiel #18
0
    private void GoToState(GameState toState)
    {
        if (_states.TryGetValue(toState, out var nextState))
        {
            _currentState?.OnStateExit();

            _currentState = nextState;
            Debug.Log($"Enter state: {_currentState.State}");
            _currentState.OnStateEnter();
        }
        else
        {
            Debug.LogError($"Unexpected {nameof(GameState)}: {toState.ToString()}");
        }
    }
        private void SwitchGameState(BaseGameState gameState)
        {
            if (_currentGameState != null)
            {
                _currentGameState.OnStateSwitched     -= CurrentGameState_OnStateSwitched;
                _currentGameState.OnEventNotification -= _currentGameState_OnEventNotification;
                _currentGameState.UnloadContent(Content);
            }

            _currentGameState = gameState;

            _currentGameState.LoadContent(Content);

            _currentGameState.OnStateSwitched     += CurrentGameState_OnStateSwitched;
            _currentGameState.OnEventNotification += _currentGameState_OnEventNotification;
        }
Beispiel #20
0
    IEnumerator Start()
    {
        yield return(PlayerCloneState.LoadAssets()); //Load our player clone state assets in

        //Spawn our player
        CharacterController playerController = Instantiate(playerPrefab).GetComponent <CharacterController>();

        //Setup player
        Debug.Assert(playerController != null, "Our player prefab does not have a character controller!");
        player.Possess(playerController);
        player.enabled = true;
        RespawnPlayer();
        //Setup camera
        mainCamera.Follow = playerController.transform;
        //Set gamestate
        currentGameState = GameStateProvider.GetCurrentGameState();
    }
        private void SwitchGameState(BaseGameState gameState)
        {
            if (_currentGameState != null)
            {
                _currentGameState.OnStateSwitched     -= CurrentGameState_OnStateSwitched;
                _currentGameState.OnEventNotification -= _currentGameState_OnEventNotification;
                _currentGameState.UnloadContent();
            }

            _currentGameState = gameState;

            _currentGameState.Initialize(Content, graphics.GraphicsDevice.Viewport.Width, graphics.GraphicsDevice.Viewport.Height);

            _currentGameState.LoadContent();

            _currentGameState.OnStateSwitched     += CurrentGameState_OnStateSwitched;
            _currentGameState.OnEventNotification += _currentGameState_OnEventNotification;
        }
        private void SwitchGameState(BaseGameState gameState)
        {
            if (_currentGameState != null)
            {
                _currentGameState.OnStateSwitched     -= CurrentGameState_OnStateSwitched;
                _currentGameState.OnEventNotification -= _currentGameState_OnEventNotification;
                _currentGameState.UnloadContent();
            }

            _currentGameState = gameState;

            _currentGameState.Initialize(Content, Window, GraphicsDevice);

            _currentGameState.LoadContent();

            _currentGameState.OnStateSwitched     += CurrentGameState_OnStateSwitched;
            _currentGameState.OnEventNotification += _currentGameState_OnEventNotification;
        }
Beispiel #23
0
    public void ChangeGameState(BaseGameState newState, bool pushPreviousState = false) {
        // destroy or push old state
        if(CurrentState != null) {
            CurrentState.OnExit -= OnExit;

            if(pushPreviousState)
                _stateStack.Push(CurrentState);
            else
                CurrentState.Dispose();
        }

        // set new state
        CurrentState = newState;

        Debug.Log("Changed state to " + CurrentState.GameState.ToString());

        CurrentState.OnExit += OnExit;
        CurrentState.EnterState();
    }
Beispiel #24
0
        public void TriggerTransition(Transition transition)
        {
            State nextStateId = _currentState.GetNextState(transition);

            if (nextStateId != State.NoState)
            {
                BaseGameState nextState = null;
                if (_gameStates.TryGetValue(nextStateId, out nextState))
                {
                    _currentState.OnExitState();
                    _currentState = nextState;
                    _currentState.OnEnterState();
                }
                else
                {
                    Debug.LogError("Trying to transition to an uncreated state: " + nextStateId.ToString());
                }
            }
        }
Beispiel #25
0
    public void RestorePreviousState(GameStates state = GameStates.None) {
        if(_stateStack.Count == 0) throw new Exception("No previous states available");

        // set target state to the previous state if none specified
        if(state == GameStates.None)
            state = (_stateStack.Peek() as BaseGameState).GameState;

        while(_stateStack.Count > 0 && CurrentState.GameState != state) {
            CurrentState.OnExit -= OnExit;
            CurrentState.Dispose();

            CurrentState = (BaseGameState)_stateStack.Pop();
        }

        if(CurrentState == null) throw new Exception("Previous state not found: " + state.ToString());

        Debug.Log("Restored state to " + CurrentState.GameState.ToString());

        CurrentState.OnExit += OnExit;
        CurrentState.EnterState();
    }
    void ChangeState(Type type)
    {
        if (_nowState == null)
        {
            _nowState = GetState(type);
            _nowState.Enter(null);
            _willStateType = null;
            return;
        }

        if (_nowState.GetType() == type)
        {
            return;
        }

        if (_willStateType != null && _willStateType == type)
        {
            return;
        }

        _willStateType = type;
        _nowState.Leave();
    }
Beispiel #27
0
 // Start is called before the first frame update
 void Start()
 {
     curState = prepareState;
     curState.Enter();
 }
 private void CurrentGameState_OnStateSwitched(object sender, BaseGameState e)
 {
     SwitchGameState(e);
 }
Beispiel #29
0
 private void OnExit(BaseGameState exitingState) {
     OnStateExit(exitingState);
 }
Beispiel #30
0
 public GameStateManager(GameManager manager) : base(manager)
 {
     GameInitState = new GameInitState(this);
 }
 public override void Enter(BaseGameState from)
 {
     throw new System.NotImplementedException();
 }
 public override void Exit(BaseGameState to)
 {
     throw new System.NotImplementedException();
 }
Beispiel #33
0
 public void Initialize(GameBoard gameboard)
 {
     _gameBoard = gameboard;
     SetupGameStates();
     _currentState = _gameStates[State.Input];
 }