aboutsummaryrefslogtreecommitdiff
path: root/src/game/game.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/game.cpp')
-rw-r--r--src/game/game.cpp37
1 files changed, 21 insertions, 16 deletions
diff --git a/src/game/game.cpp b/src/game/game.cpp
index 3bd8738..c41364a 100644
--- a/src/game/game.cpp
+++ b/src/game/game.cpp
@@ -2,7 +2,6 @@
#include <fmt/core.h>
-#include <chrono>
#include <cstdlib>
#include <iostream>
#include <utility>
@@ -12,16 +11,12 @@ Game::Game(
std::shared_ptr<ICursorController> cursor_controller,
std::shared_ptr<IGenerationTracker> generation_tracker,
std::shared_ptr<IStatusManager> status_manager,
- std::shared_ptr<IUserInputObserver> user_input_observer,
- IStatusLineSubscriberAdapterFactory<Vector2>
- vector2_statusline_subscriber_adapter_factory) noexcept
+ std::shared_ptr<IUserInputObserver> user_input_observer) noexcept
: _scene(std::move(scene)),
_cursor_controller(std::move(cursor_controller)),
_generation_tracker(std::move(generation_tracker)),
_status_manager(std::move(status_manager)),
- _user_input_observer(std::move(user_input_observer)),
- _vector2_statusline_subscriber_adapter_factory(
- vector2_statusline_subscriber_adapter_factory)
+ _user_input_observer(std::move(user_input_observer))
{
}
@@ -36,15 +31,6 @@ void Game::on_start() noexcept
_status_manager->set_section_title(StatusLineSection::E, "Generation: ");
_status_manager->set_section_title(StatusLineSection::F, "Time since last frame: ");
- std::shared_ptr<ISubscriber<Vector2>> vector2_statusline_subscriber_adapter =
- _vector2_statusline_subscriber_adapter_factory(
- _status_manager,
- {StatusLineSection::B, StatusLineSection::C});
-
- _cursor_controller->subscribe(
- CursorEvent::POSITION_CHANGE,
- vector2_statusline_subscriber_adapter);
-
const auto scene_size = _scene->size();
const auto center_position = Vector2(
@@ -95,24 +81,43 @@ void Game::on_update() noexcept
matrix->set(position - pos_offset, "#");
}
+ auto cursor_has_moved = false;
+
if (_user_input_observer->is_key_pressed('h'))
{
_move_cursor(Vector2::left());
+ cursor_has_moved = true;
}
if (_user_input_observer->is_key_pressed('j'))
{
_move_cursor(Vector2::down());
+ cursor_has_moved = true;
}
if (_user_input_observer->is_key_pressed('k'))
{
_move_cursor(Vector2::up());
+ cursor_has_moved = true;
}
if (_user_input_observer->is_key_pressed('l'))
{
_move_cursor(Vector2::right());
+ cursor_has_moved = true;
+ }
+
+ if (cursor_has_moved)
+ {
+ const auto current_pos = _cursor_controller->where();
+
+ _status_manager->set_section_body(
+ StatusLineSection::B,
+ fmt::format("{}", current_pos.get_x()));
+
+ _status_manager->set_section_body(
+ StatusLineSection::C,
+ fmt::format("{}", current_pos.get_y()));
}
if (_user_input_observer->is_key_pressed('p'))