diff --git a/Engine/headers/game.h b/Engine/headers/game.h index 9a06b47..5380c84 100644 --- a/Engine/headers/game.h +++ b/Engine/headers/game.h @@ -11,7 +11,6 @@ static int curX, curY; -extern bool isActive; extern std::vector> rooms; #define MAP_HEIGHT 5 @@ -26,7 +25,9 @@ private: nlohmann::json json; fs::path filePath = "Resources/Rooms.json"; std::ifstream stream; - + bool isActive; + + inline static Game *game_; @@ -36,7 +37,7 @@ private: public: Game(); - static bool GetIsActive() { return isActive; } + inline bool GetIsActive() const { return isActive; } bool Init(); void Run(); bool Save(); @@ -44,7 +45,18 @@ public: void ChangeRoom(Room r); Room GetCurrentRoom() { return currentRoom; } - static void SetIsActive(const bool active) { isActive = active; } + inline bool operator!() const { + if (isActive) { + return false; + } + return true; + } + + void SetIsActive(const bool active) { isActive = active; } + + static void SetGameInstance(Game * g) { + game_ = g; + } static Game &Instance() { if (game_ == nullptr) { diff --git a/Engine/src/game.cpp b/Engine/src/game.cpp index d176afe..5f891e2 100644 --- a/Engine/src/game.cpp +++ b/Engine/src/game.cpp @@ -3,15 +3,13 @@ #include #include -bool isActive; - std::vector> rooms; Game::Game() { curX = 0; curY = 0; + isActive = false; progress = 0; - Init(); } bool Game::Init() { @@ -72,7 +70,7 @@ void Game::ChangeRoom(Room r) { } int Quit(const std::string &n) { - isActive = false; + Game::Instance().SetIsActive(false); return 0; } diff --git a/main.cpp b/main.cpp index 6069beb..e075dd2 100644 --- a/main.cpp +++ b/main.cpp @@ -3,7 +3,11 @@ int main(int argc, char *argv[]) { Game game; // Calls default constructor which Initializes GAME - while (Game::GetIsActive()) { + if (!game) { + game.Init(); + Game::SetGameInstance(&game); + } + while (game.GetIsActive()) { game.Run(); }