#include "backend/Location.h" #include "backend/Dungeon.h" #include "backend/Exception.h" #include "backend/print.h" #include "../GameController.h" #include "../strings.h" using namespace std; static const unordered_map direction_map = { { "noord", Direction::NORTH }, { "oost", Direction::EAST }, { "zuid", Direction::SOUTH }, { "west", Direction::WEST }, }; void GameController::cmd_go(string & argv) { string direction_str = str_consume_arg(argv); 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 = player.get_location().get_exit(direction); if (next_location == nullptr) throw Exception("er is geen uitgang in deze richting"); this->dungeon->update(); if (!player.is_dead()) { player.set_location(*next_location); lprtf("Je staat nu bij de locatie %s\n", player.get_location().get_name().c_str()); } }