/// <summary>Pushes the specified state onto the state stack</summary> /// <param name="state">State that will be pushed onto the stack</param> public void Push(GameState state) { if(this.activeGameStates.Count > 0) { // Pause the state the was previously active this.activeGameStates.Peek().InternalPause(); } try { this.activeGameStates.Push(state); // Push the new state onto the stack and notify it that it has become active try { state.InternalEntered(); } catch(Exception) { this.activeGameStates.Pop(); throw; } } catch(Exception) { if(this.activeGameStates.Count > 0) { this.activeGameStates.Peek().InternalResume(); } throw; } }
/// <summary>Pushes the specified state onto the state stack</summary> /// <param name="state">State that will be pushed onto the stack</param> public void Push(GameState state) { if (this.activeGameStates.Count > 0) { // Pause the state the was previously active this.activeGameStates.Peek().InternalPause(); } try { this.activeGameStates.Push(state); // Push the new state onto the stack and notify it that it has become active try { state.InternalEntered(); } catch (Exception) { this.activeGameStates.Pop(); throw; } } catch (Exception) { if (this.activeGameStates.Count > 0) { this.activeGameStates.Peek().InternalResume(); } throw; } }
/// <summary>Takes the currently active game state from the stack</summary> public void Pop() { GameState topMostGameState = this.activeGameStates.Peek(); topMostGameState.InternalLeaving(); this.activeGameStates.Pop(); if (this.activeGameStates.Count > 0) { try { this.activeGameStates.Peek().InternalResume(); } catch (Exception) { topMostGameState.InternalEntered(); this.activeGameStates.Push(topMostGameState); throw; } } }