aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/engine/engine.cpp14
-rw-r--r--src/game/game.cpp19
-rw-r--r--src/game/game.hpp2
-rw-r--r--src/interfaces/game.hpp2
4 files changed, 31 insertions, 6 deletions
diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp
index ed75394..b0456a3 100644
--- a/src/engine/engine.cpp
+++ b/src/engine/engine.cpp
@@ -2,7 +2,10 @@
#include "util/function.hpp"
+#include <fmt/core.h>
+
#include <chrono>
+#include <exception>
#include <thread>
#include <utility>
@@ -30,7 +33,16 @@ void CLIGameEngine::start() noexcept
auto game = _game_factory(_scene, _cursor_controller, _user_input_observer);
- game->on_start();
+ try
+ {
+ game->on_start();
+ }
+ catch (const std::exception &error)
+ {
+ _scene->leave();
+ fmt::print("Error: {}\n", error.what());
+ return;
+ }
std::atexit(normalize_lambda(
[this, &game]()
diff --git a/src/game/game.cpp b/src/game/game.cpp
index 2f6c09c..e969fe1 100644
--- a/src/game/game.cpp
+++ b/src/game/game.cpp
@@ -16,6 +16,7 @@
#include <cstdlib>
#include <filesystem>
#include <iostream>
+#include <stdexcept>
#include <utility>
Game::Game(
@@ -42,7 +43,7 @@ Game::Game(
{
}
-void Game::on_start() noexcept
+void Game::on_start()
{
const auto scene_size = _scene->size();
@@ -55,8 +56,20 @@ void Game::on_start() noexcept
const auto statusline_section_d_length = 20;
const auto statusline_section_e_length = 25;
const auto statusline_section_f_length = 30;
- const auto statusline_section_g_length = 30;
- const auto statusline_section_h_length = 20;
+ const auto statusline_section_g_length = 20;
+ const auto statusline_section_h_length = 3;
+
+ const auto statusline_section_length_total =
+ statusline_section_a_length + statusline_section_b_length +
+ statusline_section_c_length + statusline_section_d_length +
+ statusline_section_e_length + statusline_section_f_length +
+ statusline_section_g_length + statusline_section_h_length;
+
+ if (statusline_section_length_total > scene_size.get_width())
+ {
+ throw std::runtime_error(
+ "To small window terminal size. The statusline doesn't fit");
+ }
statusline->set_section_length(StatusLineSection::A, statusline_section_a_length);
statusline->set_section_length(StatusLineSection::B, statusline_section_b_length);
diff --git a/src/game/game.hpp b/src/game/game.hpp
index e69ce46..ed5a00f 100644
--- a/src/game/game.hpp
+++ b/src/game/game.hpp
@@ -64,7 +64,7 @@ public:
std::shared_ptr<ICellHelper> cell_helper,
std::shared_ptr<IRLEReader> rle_reader) noexcept;
- void on_start() noexcept override;
+ void on_start() override;
void on_update() noexcept override;
diff --git a/src/interfaces/game.hpp b/src/interfaces/game.hpp
index b6d7f36..6d0251f 100644
--- a/src/interfaces/game.hpp
+++ b/src/interfaces/game.hpp
@@ -14,7 +14,7 @@ class IGame
public:
virtual ~IGame() noexcept = default;
- virtual void on_start() noexcept = 0;
+ virtual void on_start() = 0;
virtual void on_update() noexcept = 0;