#include #include "Player.h" #include "print.h" #include "Dungeon.h" #include "util.h" Player::Player(Dungeon & dungeon) : dungeon(dungeon) { } float Player::get_attack() const { if (this->cheating) return 1.f; return this->attack_chance; } unsigned Player::get_health() const { return this->health_points; } bool Player::is_dead() const { return this->health_points == 0; } void Player::take_damage(unsigned int dmg) { if (this->cheating) return; if (this->is_dead()) return; dmg = min(dmg, this->health_points); if (this->armor != nullptr) dmg = max(0u, dmg - this->armor->get_protection()); this->health_points -= dmg; auto & hp = this->health_points; lprtf("Je hebt %s%d levenspunt%s over.\n", hp > 0 ? "nog " : "", hp, hp == 1 ? "" : "en"); if (this->is_dead()) { lprtf("Je bent dood gegaan!\n"); } } Location & Player::get_location() const { assert(this->location != nullptr); return *this->location; } void Player::set_location(Location & location) { this->location = &location; } void Player::equip(WeaponObject * weapon) { if (weapon == nullptr) return; lprtf("Je "); if (this->weapon != nullptr) { lprtf("laat %s vallen en ", this->weapon->get_name().c_str()); this->inventory.push_back(this->weapon); } this->weapon = weapon; lprtf("pakt %s vast.\n", this->weapon->get_name().c_str()); } void Player::equip(ArmorObject * armor) { if (armor == nullptr) return; lprtf("Je "); if (this->armor != nullptr) { lprtf("trekt %s uit en ", this->armor->get_name().c_str()); this->inventory.push_back(this->armor); } this->armor = armor; lprtf("doet %s aan.\n", this->armor->get_name().c_str()); }