aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/game/game.cpp30
-rw-r--r--src/game/game.hpp2
2 files changed, 21 insertions, 11 deletions
diff --git a/src/game/game.cpp b/src/game/game.cpp
index 9d8c246..2eef4cf 100644
--- a/src/game/game.cpp
+++ b/src/game/game.cpp
@@ -86,23 +86,31 @@ void Game::on_update() noexcept
switch (pressed_key)
{
case 'h':
- _move_cursor(Vector2::left());
- cursor_has_moved = true;
+ if (_move_cursor(Vector2::left()))
+ {
+ cursor_has_moved = true;
+ }
break;
case 'j':
- _move_cursor(Vector2::down());
- cursor_has_moved = true;
+ if (_move_cursor(Vector2::down()))
+ {
+ cursor_has_moved = true;
+ }
break;
case 'k':
- _move_cursor(Vector2::up());
- cursor_has_moved = true;
+ if (_move_cursor(Vector2::up()))
+ {
+ cursor_has_moved = true;
+ }
break;
case 'l':
- _move_cursor(Vector2::right());
- cursor_has_moved = true;
+ if (_move_cursor(Vector2::right()))
+ {
+ cursor_has_moved = true;
+ }
break;
case 'q':
@@ -264,7 +272,7 @@ void Game::on_exit() const noexcept
std::cout.flush();
}
-void Game::_move_cursor(const Vector2 &direction) noexcept
+auto Game::_move_cursor(const Vector2 &direction) noexcept -> bool
{
const auto current_position = _cursor_controller->where();
@@ -274,10 +282,12 @@ void Game::_move_cursor(const Vector2 &direction) noexcept
if (scene_size.validate_coords(dest_position) != CoordsValidation::VALID)
{
- return;
+ return false;
}
_cursor_controller->move_to(dest_position);
+
+ return true;
}
void Game::_set_space(
diff --git a/src/game/game.hpp b/src/game/game.hpp
index b5b69cf..d629400 100644
--- a/src/game/game.hpp
+++ b/src/game/game.hpp
@@ -55,7 +55,7 @@ private:
std::list<Vector2> _living_cell_positions;
- void _move_cursor(const Vector2 &direction) noexcept;
+ auto _move_cursor(const Vector2 &direction) noexcept -> bool;
void _set_space(
const std::shared_ptr<IMatrix<IScene::MatrixElement>> &matrix,