aboutsummaryrefslogtreecommitdiff
path: root/src/game/game.cpp
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-03-03 20:40:29 +0100
committerHampusM <hampus@hampusmat.com>2022-06-13 17:56:54 +0200
commitd27f1a89266e141a944f88e9080bdeca95c49da3 (patch)
treebe78081c7b71f335b59057d25bc817bcb1306d36 /src/game/game.cpp
parentb8e33c5aa3417bdf7989bef55cc449f75f806b76 (diff)
refactor: add game initializer
Diffstat (limited to 'src/game/game.cpp')
-rw-r--r--src/game/game.cpp82
1 files changed, 35 insertions, 47 deletions
diff --git a/src/game/game.cpp b/src/game/game.cpp
index ee3a2b8..559f9a0 100644
--- a/src/game/game.cpp
+++ b/src/game/game.cpp
@@ -2,58 +2,46 @@
#include <utility>
-Game::Game(std::shared_ptr<IScene> scene, std::shared_ptr<IInputHandler> input_handler,
- std::shared_ptr<CursorController> cursor_controller)
- : _scene(std::move(scene)),
- _input_handler(std::move(input_handler)),
- _cursor_controller(std::move(cursor_controller))
+Game::Game(std::shared_ptr<CursorController> cursor_controller)
+ : _cursor_controller(std::move(cursor_controller))
{
}
-void Game::run()
+void Game::run(IScene &scene, IInputHandler &input_handler)
{
- _scene->enter();
-
- _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.attach('q',
+ [&input_handler, &scene]()
+ {
+ input_handler.leave_raw_mode();
+ scene.leave();
+ exit(EXIT_SUCCESS);
+ });
auto cursor_controller = _cursor_controller;
- _input_handler->attach('k',
- [&cursor_controller]()
- {
- cursor_controller->move<Direction::UP>(1U);
- });
-
- _input_handler->attach('j',
- [&cursor_controller]()
- {
- cursor_controller->move<Direction::DOWN>(1U);
- });
-
- _input_handler->attach('h',
- [&cursor_controller]()
- {
- cursor_controller->move<Direction::LEFT>(1U);
- });
-
- _input_handler->attach('l',
- [&cursor_controller]()
- {
- cursor_controller->move<Direction::RIGHT>(1U);
- });
-
- _input_handler->listen();
-
- _scene->leave();
+ input_handler.attach('k',
+ [&cursor_controller]()
+ {
+ cursor_controller->move<Direction::UP>(1U);
+ });
+
+ input_handler.attach('j',
+ [&cursor_controller]()
+ {
+ cursor_controller->move<Direction::DOWN>(1U);
+ });
+
+ input_handler.attach('h',
+ [&cursor_controller]()
+ {
+ cursor_controller->move<Direction::LEFT>(1U);
+ });
+
+ input_handler.attach('l',
+ [&cursor_controller]()
+ {
+ cursor_controller->move<Direction::RIGHT>(1U);
+ });
+
+ input_handler.listen();
}