diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-29 21:30:38 +0100 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-29 21:30:38 +0100 |
commit | a04cb74fee079e3ee43ae5fae32fc2674409822c (patch) | |
tree | 403e681a768ee68b54569e93d98e741878cd7975 /frontend/cmd | |
parent | 9283e1eb66d6ff96b02f317e28cb6ff060953cdf (diff) |
implement movement
Diffstat (limited to 'frontend/cmd')
-rw-r--r-- | frontend/cmd/go.cpp | 25 | ||||
-rw-r--r-- | frontend/cmd/query.cpp | 29 |
2 files changed, 54 insertions, 0 deletions
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<string, Direction> 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 <noord|zuid|oost|west>\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; } diff --git a/frontend/cmd/query.cpp b/frontend/cmd/query.cpp index 48cbb55..367d6cd 100644 --- a/frontend/cmd/query.cpp +++ b/frontend/cmd/query.cpp @@ -1,6 +1,35 @@ +#include "backend/Location.h" + #include "../Player.h" +#include "../print.h" + +using namespace std; + +static const unordered_map<Direction, string> direction_map = { + { Direction::NORTH, "Noord" }, + { Direction::EAST, "Oost" }, + { Direction::SOUTH, "Zuid" }, + { Direction::WEST, "West" }, +}; FollowupAction Player::cmd_query(Argv argv) { + lprtf("Je staat bij de locatie %s.\n", this->location.get_name()); + lprtf("%s\n", this->location.get_description()); + + // TODO: visible objects + + lprtf("Uitgangen: "); + bool first = true; + for (Direction direction : DIRECTIONS) { + if (this->location.get_exit(direction) == nullptr) continue; + if (!first) lprtf(", "); + lprtf("%s", direction_map.at(direction).c_str()); + first = false; + } + lprtf("\n"); + + // TODO: enemies + return FollowupAction::NONE; } |