aboutsummaryrefslogtreecommitdiff
path: root/backend/Enemy.cpp
blob: 15e66eda5e720a0e53093e45f74669c53991cebc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include "Enemy.h"

Enemy::Enemy(const String & name, const String & description) : name(name), description(description) { }

void Enemy::set_name(const String & name) { this->name = name; }
const String & Enemy::get_name() const { return this->name; }

void Enemy::set_description(const String & description) { this->description = description; }
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;
}