GameStateManager.hxx 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #pragma once
  2. #ifndef SNAKE_GAMESTATEMANAGER_HXX
  3. #define SNAKE_GAMESTATEMANAGER_HXX
  4. #include "LoadingState.hxx"
  5. #include "SplashState.hxx"
  6. #include "MenuState.hxx"
  7. #include "PlayingState.hxx"
  8. #include "GameOverState.hxx"
  9. #include "HighScoreState.hxx"
  10. #include "CreditsState.hxx"
  11. #include <stack>
  12. #include "../NonCopyable.hxx"
  13. class SDLWindow;
  14. enum class GameStates {
  15. Loading,
  16. Splash,
  17. MainMenu,
  18. Game,
  19. GameOver,
  20. HighScores,
  21. Credits,
  22. };
  23. class GameStateManager final : private NonCopyable {
  24. public:
  25. explicit GameStateManager(SDLWindow& window);
  26. ~GameStateManager();
  27. GameState* current();
  28. GameState* parent();
  29. void push_state(GameStates new_state);
  30. void pop_state();
  31. void replace_state(GameStates new_state);
  32. SDLWindow& window()
  33. {
  34. return window_;
  35. }
  36. private:
  37. SDLWindow& window_;
  38. std::stack<GameStates> states_;
  39. GameState* enum_to_state(GameStates state);
  40. LoadingState loading_;
  41. SplashState splash_;
  42. MenuState menu_;
  43. PlayingState game_;
  44. GameOverState game_over_;
  45. HighScoreState high_score_;
  46. CreditsState credits_;
  47. };
  48. #endif // SNAKE_GAMESTATEMANAGER_HXX