From 798948dbe6f012e194f053c4e862cf697f30b793 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Fri, 1 Nov 2024 10:18:22 +0100 Subject: more WIP (move some Player things to backend) --- backend/Dungeon.cpp | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) (limited to 'backend/Dungeon.cpp') 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 + #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 enemies = player_location->get_enemies(); +Dungeon::Dungeon() : player(*this) { } +void Dungeon::update() { + ListRange 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 & 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; } -- cgit v1.2.3