diff options
author | HampusM <hampus@hampusmat.com> | 2022-02-28 21:30:30 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-06-13 17:56:54 +0200 |
commit | ede689d23e57c9b701ab19aa9112a0b2368865c9 (patch) | |
tree | e8c7afc7b2e5caf43b1b0c52356c0596021f25cb /src/game/game.cpp | |
parent | f0883534b3303cf2b74f3ab51efe16615d2561a9 (diff) |
feat: add input handler & quitting with 'q'
Diffstat (limited to 'src/game/game.cpp')
-rw-r--r-- | src/game/game.cpp | 23 |
1 files changed, 18 insertions, 5 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(); } |