aboutsummaryrefslogtreecommitdiff
path: root/frontend/cmd/go.cpp
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-11-01 17:32:53 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-11-01 17:32:53 +0100
commitb20f46c15dce8b196dbb8890890978947745e094 (patch)
treed9defa84717ffa843fd11b05d0e856473d6d8d59 /frontend/cmd/go.cpp
parenta7e84b60366c78b131d43157980fbe4c2df655e6 (diff)
change flow architecture
Diffstat (limited to 'frontend/cmd/go.cpp')
-rw-r--r--frontend/cmd/go.cpp25
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();
}