diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-11-01 17:32:53 +0100 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-11-01 17:32:53 +0100 |
commit | b20f46c15dce8b196dbb8890890978947745e094 (patch) | |
tree | d9defa84717ffa843fd11b05d0e856473d6d8d59 /frontend/cmd/go.cpp | |
parent | a7e84b60366c78b131d43157980fbe4c2df655e6 (diff) |
change flow architecture
Diffstat (limited to 'frontend/cmd/go.cpp')
-rw-r--r-- | frontend/cmd/go.cpp | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/frontend/cmd/go.cpp b/frontend/cmd/go.cpp index 6a5f3b2..5fd7c93 100644 --- a/frontend/cmd/go.cpp +++ b/frontend/cmd/go.cpp @@ -1,8 +1,10 @@ #include "backend/Location.h" #include "backend/print.h" +#include "backend/Dungeon.h" #include "../GameController.h" #include "../strings.h" +#include "../Exception.h" using namespace std; @@ -13,21 +15,20 @@ static const unordered_map<string, Direction> direction_map = { { "west", Direction::WEST }, }; -FollowupAction GameController::cmd_go(string & argv) { +void GameController::cmd_go(string & argv) { string direction_str = str_consume_arg(argv); - if (direction_str.size() == 0 || !direction_map.contains(direction_str)) { - lprtf("Fout, gebruik: Ga <noord|zuid|oost|west>\n"); - return FollowupAction::NONE; - } + if (direction_str.size() == 0) + throw Exception("Dit commando heeft nog een argument met een richting nodig"); + if (!direction_map.contains(direction_str)) + throw Exception("Onbekende richting \"%s\", probeer noord|zuid|oost|west", direction_str.c_str()); + Player & player = this->dungeon->get_player(); Direction direction = direction_map.at(direction_str); - Location * next_location = this->player.get_location().get_exit(direction); - if (next_location == nullptr) { - lprtf("Er is geen uitgang in deze richting!\n"); - return FollowupAction::NONE; - } + Location * next_location = player.get_location().get_exit(direction); + if (next_location == nullptr) + throw Exception("Er is geen uitgang in deze richting"); - this->player.set_location(*next_location); - return FollowupAction::UPDATE; + player.set_location(*next_location); + this->dungeon->update(); } |