aboutsummaryrefslogtreecommitdiff
path: root/backend/Enemy.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'backend/Enemy.cpp')
-rw-r--r--backend/Enemy.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/backend/Enemy.cpp b/backend/Enemy.cpp
index 9d3b26d..15e66ed 100644
--- a/backend/Enemy.cpp
+++ b/backend/Enemy.cpp
@@ -10,3 +10,18 @@ const String & Enemy::get_description() const { return this->description; }
unsigned Enemy::get_health() const { return this->health_points; }
+const String & Enemy::get_displayname() const {
+ static String displayname;
+ displayname = String::fmt("%s%s", this->name.c_str(), this->health_points == 0 ? " [verslagen]" : "");
+ return displayname;
+}
+
+static inline unsigned min(unsigned a, unsigned b) {
+ return a < b ? a : b;
+}
+
+void Enemy::take_damage(unsigned int dmg) {
+ dmg = min(dmg, this->health_points);
+ this->health_points -= dmg;
+}
+