diff options
Diffstat (limited to 'backend/Location.cpp')
-rw-r--r-- | backend/Location.cpp | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/backend/Location.cpp b/backend/Location.cpp index 2177d8a..2de4676 100644 --- a/backend/Location.cpp +++ b/backend/Location.cpp @@ -3,6 +3,7 @@ #include "ListIterator.h" #include "Enemy.h" #include "Object.h" +#include "Exception.h" Direction operator - (const Direction & rhs) { return static_cast<Direction>((rhs + 2) % 4); @@ -15,7 +16,7 @@ Direction random_direction() { Direction random_direction(const Location & location) { List<Direction> valid = {}; for (Direction direction : DIRECTIONS) { - if (location.get_exit(direction) == nullptr) continue; + if (!location.has_exit(direction)) continue; valid.push_back(direction); } return valid[RNG::get().rand_int(valid.size())]; @@ -29,11 +30,16 @@ const String & Location::get_name() const { return this->name; } void Location::set_description(const String & description) { this->description = description; } const String & Location::get_description() const { return this->description; } -void Location::set_exit(Direction dir, Location * location) { - this->edges[dir] = location; +void Location::set_exit(Direction dir, Location & location) { + this->edges[dir] = &location; } -Location * Location::get_exit(Direction dir) const { - return this->edges[dir]; +bool Location::has_exit(Direction dir) const { + return this->edges[dir] != nullptr; +} +Location & Location::get_exit(Direction dir) const { + if (!this->has_exit(dir)) + throw Exception("er is geen uitgang in deze richting"); + return *this->edges[dir]; } void Location::add_visible_object(Object * object) { |