From a04cb74fee079e3ee43ae5fae32fc2674409822c Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Tue, 29 Oct 2024 21:30:38 +0100 Subject: implement movement --- frontend/cmd/go.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'frontend/cmd/go.cpp') diff --git a/frontend/cmd/go.cpp b/frontend/cmd/go.cpp index 2aaec08..cbe8e7c 100644 --- a/frontend/cmd/go.cpp +++ b/frontend/cmd/go.cpp @@ -1,6 +1,31 @@ +#include "backend/Location.h" + #include "../Player.h" +#include "../print.h" + +using namespace std; + +static const unordered_map direction_map = { + { "noord", Direction::NORTH }, + { "oost", Direction::EAST }, + { "zuid", Direction::SOUTH }, + { "west", Direction::WEST }, +}; FollowupAction Player::cmd_go(Argv argv) { + if (argv.size() == 0 || !direction_map.contains(argv[0])) { + lprtf("Fout, gebruik: Ga \n"); + return FollowupAction::NONE; + } + + Direction direction = direction_map.at(argv[0]); + Location * next_location = this->location.get_exit(direction); + if (next_location == nullptr) { + lprtf("Er is geen uitgang in deze richting!\n"); + return FollowupAction::NONE; + } + + this->location = *next_location; return FollowupAction::UPDATE; } -- cgit v1.2.3