aboutsummaryrefslogtreecommitdiff
path: root/src/game
diff options
context:
space:
mode:
Diffstat (limited to 'src/game')
-rw-r--r--src/game/game.cpp63
-rw-r--r--src/game/game.hpp20
2 files changed, 62 insertions, 21 deletions
diff --git a/src/game/game.cpp b/src/game/game.cpp
index 45e6a79..5df3935 100644
--- a/src/game/game.cpp
+++ b/src/game/game.cpp
@@ -3,21 +3,58 @@
#include "commands/insert_cell.hpp"
#include "commands/move_cursor.hpp"
#include "commands/quit.hpp"
+#include "strings.hpp"
-void Game::run() noexcept {}
+#include <fmt/core.h>
+#include <iostream>
-std::unordered_map<char, std::shared_ptr<ICommand>> Game::get_input_config(
- const std::shared_ptr<IWindow> &window, const std::shared_ptr<IScene> &scene,
- const std::shared_ptr<ICursorController> &cursor_controller) const noexcept
+Game::Game(const std::shared_ptr<IWindow> &window, const std::shared_ptr<IScene> &scene,
+ const std::shared_ptr<ICursorController> &cursor_controller) noexcept
+ : _window(window), _scene(scene), _cursor_controller(cursor_controller)
+{
+}
+
+void Game::on_start() noexcept
+{
+ const auto window_size = _window->size();
+
+ const auto center_position =
+ Vector2({.x = static_cast<Vector2::Value>(window_size.get_width()) / 2,
+ .y = static_cast<Vector2::Value>(window_size.get_height()) / 2});
+
+ _cursor_controller->move_to(center_position);
+
+ _scene->write_status(fmt::format(STATUS_BAR_COORDINATES,
+ fmt::arg("x", center_position.get_x()),
+ fmt::arg("y", center_position.get_y())));
+}
+
+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();
+}
+
+std::unordered_map<char, std::shared_ptr<ICommand>>
+Game::get_input_config() const noexcept
{
return {{'q', std::make_shared<QuitCommand>()},
- {'i', std::make_shared<InsertCellCommand>(cursor_controller, scene)},
- {'k', std::make_shared<MoveCursorCommand>(Vector2::up(), cursor_controller,
- scene, window)},
- {'j', std::make_shared<MoveCursorCommand>(Vector2::down(), cursor_controller,
- scene, window)},
- {'h', std::make_shared<MoveCursorCommand>(Vector2::left(), cursor_controller,
- scene, window)},
- {'l', std::make_shared<MoveCursorCommand>(Vector2::right(), cursor_controller,
- scene, window)}};
+ {'i', std::make_shared<InsertCellCommand>(_cursor_controller, _scene)},
+ {'k', std::make_shared<MoveCursorCommand>(Vector2::up(), _cursor_controller,
+ _scene, _window)},
+ {'j', std::make_shared<MoveCursorCommand>(Vector2::down(), _cursor_controller,
+ _scene, _window)},
+ {'h', std::make_shared<MoveCursorCommand>(Vector2::left(), _cursor_controller,
+ _scene, _window)},
+ {'l', std::make_shared<MoveCursorCommand>(
+ Vector2::right(), _cursor_controller, _scene, _window)}};
}
diff --git a/src/game/game.hpp b/src/game/game.hpp
index 9ec5b41..2493a42 100644
--- a/src/game/game.hpp
+++ b/src/game/game.hpp
@@ -1,6 +1,5 @@
#pragma once
-#include "DI/auto_wirable.hpp"
#include "interfaces/cursor.hpp"
#include "interfaces/game.hpp"
#include "interfaces/scene.hpp"
@@ -8,16 +7,21 @@
#include <memory>
-class Game : public IGame, public AutoWirable<IGame, Game>
+class Game : public IGame
{
public:
- Game() noexcept = default;
+ Game(const std::shared_ptr<IWindow> &window, const std::shared_ptr<IScene> &scene,
+ const std::shared_ptr<ICursorController> &cursor_controller) noexcept;
- void run() noexcept override;
+ void on_start() noexcept override;
+
+ void on_exit() const noexcept override;
[[nodiscard]] std::unordered_map<char, std::shared_ptr<ICommand>>
- get_input_config(const std::shared_ptr<IWindow> &window,
- const std::shared_ptr<IScene> &scene,
- const std::shared_ptr<ICursorController> &cursor_controller)
- const noexcept override;
+ get_input_config() const noexcept override;
+
+private:
+ const std::shared_ptr<IWindow> &_window;
+ const std::shared_ptr<IScene> &_scene;
+ const std::shared_ptr<ICursorController> &_cursor_controller;
};