aboutsummaryrefslogtreecommitdiff
path: root/src/game/game.cpp
blob: 559f9a03275e390bb7404182b95760febb89a0d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "game.hpp"

#include <utility>

Game::Game(std::shared_ptr<CursorController> cursor_controller)
	: _cursor_controller(std::move(cursor_controller))
{
}

void Game::run(IScene &scene, IInputHandler &input_handler)
{
	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();
}