diff options
Diffstat (limited to 'src/game')
-rw-r--r-- | src/game/game.cpp | 23 | ||||
-rw-r--r-- | src/game/game.hpp | 7 |
2 files changed, 23 insertions, 7 deletions
diff --git a/src/game/game.cpp b/src/game/game.cpp index 2c99c6a..2b09470 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -1,15 +1,28 @@ #include "game.hpp" -#include <chrono> -#include <thread> - -Game::Game(std::shared_ptr<IScene> scene) : _scene(std::move(scene)) {} +Game::Game(std::shared_ptr<IScene> scene, std::shared_ptr<IInputHandler> input_handler) + : _scene(std::move(scene)), _input_handler(std::move(input_handler)) +{ +} void Game::run() { _scene->enter(); - std::this_thread::sleep_for(std::chrono::seconds(3)); + _input_handler->enter_raw_mode(); + + auto scene = _scene; + auto input_handler = _input_handler; + + _input_handler->attach('q', + [&input_handler, &scene]() + { + input_handler->leave_raw_mode(); + scene->leave(); + exit(EXIT_SUCCESS); + }); + + _input_handler->listen(); _scene->leave(); } diff --git a/src/game/game.hpp b/src/game/game.hpp index e7d91d6..bc37c91 100644 --- a/src/game/game.hpp +++ b/src/game/game.hpp @@ -2,17 +2,20 @@ #include "DI/auto_wirable.hpp" #include "interfaces/game.hpp" +#include "interfaces/input.hpp" #include "interfaces/scene.hpp" #include <memory> -class Game : public IGame, public AutoWirable<IGame, Game, IScene> +class Game : public IGame, public AutoWirable<IGame, Game, IScene, IInputHandler> { public: - explicit Game(std::shared_ptr<IScene> scene); + explicit Game(std::shared_ptr<IScene> scene, + std::shared_ptr<IInputHandler> input_handler); void run() override; private: std::shared_ptr<IScene> _scene; + std::shared_ptr<IInputHandler> _input_handler; }; |