#include "game.hpp" #include "commands/insert_cell.hpp" #include "commands/move_cursor.hpp" #include "commands/quit.hpp" #include "commands/toggle_pause.hpp" #include #include #include Game::Game(std::shared_ptr window, std::shared_ptr scene, std::shared_ptr cursor_controller, std::shared_ptr statusline, std::shared_ptr generation_tracker, std::shared_ptr status_updater) noexcept : _window(std::move(window)), _scene(std::move(scene)), _cursor_controller(std::move(cursor_controller)), _statusline(std::move(statusline)), _generation_tracker(std::move(generation_tracker)), _status_updater(std::move(status_updater)) { } void Game::on_start() noexcept { _statusline->initialize_background(); _cursor_controller->subscribe(CursorEvent::POSITION_CHANGE, _status_updater); const auto window_size = _window->size(); const auto center_position = Vector2({.x = static_cast(window_size.get_width()) / 2, .y = static_cast(window_size.get_height()) / 2}); _cursor_controller->move_to(center_position); _status_updater->update(center_position); } void Game::on_update() noexcept {} void Game::on_exit() const noexcept { for (auto row : *_scene->get_matrix()) { for (auto &col : row) { fmt::print("{}", col); } fmt::print("\n"); } std::cout.flush(); } auto Game::get_input_config() const noexcept -> std::unordered_map> { return {{'q', std::make_shared()}, {'i', std::make_shared(_cursor_controller, _scene)}, {'p', std::make_shared(_generation_tracker, _statusline)}, {'k', std::make_shared(Vector2::up(), _cursor_controller, _window)}, {'j', std::make_shared(Vector2::down(), _cursor_controller, _window)}, {'h', std::make_shared(Vector2::left(), _cursor_controller, _window)}, {'l', std::make_shared(Vector2::right(), _cursor_controller, _window)}}; }