Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// <summary>
- /// Represents a hierarchical state machine to manage macro flow control in the game.
- /// </summary>
- public class GameStateMachine
- {
- Stack<GameState> states;
- /// <summary>
- /// Gets the active game state.
- /// </summary>
- public GameState Current
- {
- get
- {
- if (states.Count == 0) return null;
- else return states.Peek();
- }
- }
- public void Update()
- {
- Current.Update();
- }
- public void Draw()
- {
- Current.Draw();
- }
- }
- /// <summary>
- /// Represents a logical state of the game within the structure of a <see cref="GameStateMachine"/>.
- /// </summary>
- public abstract class GameState
- {
- /// <summary>
- /// Allows the state to implement custom logic.
- /// </summary>
- public virtual void Update() { }
- /// <summary>
- /// Allows the state to implement custom rendering.
- /// </summary>
- public virtual void Draw() { }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement