aboutsummaryrefslogtreecommitdiff
path: root/backend/Dungeon.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'backend/Dungeon.cpp')
-rw-r--r--backend/Dungeon.cpp31
1 files changed, 22 insertions, 9 deletions
diff --git a/backend/Dungeon.cpp b/backend/Dungeon.cpp
index 30d6068..ad721b4 100644
--- a/backend/Dungeon.cpp
+++ b/backend/Dungeon.cpp
@@ -1,14 +1,15 @@
+#include <assert.h>
+
#include "Location.h"
#include "Dungeon.h"
#include "RNG.h"
-#include "backend/ListIterator.h"
+#include "ListIterator.h"
#include "print.h"
-void Dungeon::update(Location * player_location) {
- this->player_location = player_location;
-
- ListRange<Enemy *> enemies = player_location->get_enemies();
+Dungeon::Dungeon() : player(*this) { }
+void Dungeon::update() {
+ ListRange<Enemy *> enemies = this->player.get_location().get_enemies();
if (enemies.size() > 0)
this->update_attacks(enemies);
else
@@ -17,6 +18,14 @@ void Dungeon::update(Location * player_location) {
void Dungeon::update_attacks(ListRange<Enemy *> & enemies) {
lprtf(":: De vijand%s in je locatie vallen aan! ::\n", enemies.size() == 1 ? "" : "en");
+ RNG & rng = RNG::get();
+ for (Enemy * enemy : enemies) {
+ if (rng.rand_double() < enemy->get_attack()) continue;
+
+ unsigned damage = rng.rand_int(enemy->get_damage_min(), enemy->get_damage_max() + 1);
+ this->player.take_damage(damage);
+ lprtf("%s raakt en doet %d punt schade.\n", enemy->get_displayname().c_str(), damage);
+ }
}
void Dungeon::update_movement() {
@@ -31,7 +40,7 @@ void Dungeon::update_movement() {
location->remove_enemy(enemy);
Location * new_location = location->get_exit(direction);
new_location->add_enemy(enemy);
- if (player_location == new_location)
+ if (&this->player.get_location() == new_location)
lprtf("%s komt de huidige locatie binnen\n", enemy->get_name().c_str());
moved = true;
}
@@ -42,10 +51,14 @@ void Dungeon::add_location(Location * location) {
this->locations.push_back(location);
}
-Location * Dungeon::get_start_location() {
+Location & Dungeon::get_start_location() {
size_t size = this->locations.size();
- if (size == 0) return nullptr;
+ assert(size > 0);
size_t index = RNG::get().rand_int(size);
- return this->locations[index];
+ return *this->locations[index];
+}
+
+Player & Dungeon::get_player() {
+ return this->player;
}