aboutsummaryrefslogtreecommitdiff
path: root/backend/Player.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'backend/Player.cpp')
-rw-r--r--backend/Player.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/backend/Player.cpp b/backend/Player.cpp
index 4180458..f2bc526 100644
--- a/backend/Player.cpp
+++ b/backend/Player.cpp
@@ -16,15 +16,25 @@ 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;
- lprtf("Je hebt nog %d levenspunten over.\n", this->health_points);
+ 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 {