Game Manager
Central Game State
The GameManager is a common design pattern used in game development. It's essentially a script or object that acts as a central controller or orchestrator for the overall game. It oversees and coordinates many different parts of the game, such as keeping track of the player's progress, managing the player, and coordinating the whole scene.
In this case, its job is to keep track of the play State of the game and manage the Win / Loss states by playing sounds and enabling the user to restart the game.
#pragma once
#include <SFML/Audio/Sound.hpp>
#include <cstdint>
#include "engine/node.h"
namespace game {
class GameManager : public ng::Node {
public:
enum class State : uint8_t {
BEGIN = 0,
PLAY,
WON,
LOST,
};
explicit GameManager(ng::App* app);
void Win();
void Lose();
State GetState() const;
protected:
void OnAdd() override;
void Update() override;
private:
State state_{};
sf::Sound lose_sound_;
};
} // namespace gameLast updated