diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-11-01 17:32:53 +0100 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-11-01 17:32:53 +0100 |
commit | b20f46c15dce8b196dbb8890890978947745e094 (patch) | |
tree | d9defa84717ffa843fd11b05d0e856473d6d8d59 /backend | |
parent | a7e84b60366c78b131d43157980fbe4c2df655e6 (diff) |
change flow architecture
Diffstat (limited to 'backend')
-rw-r--r-- | backend/Dungeon.cpp | 2 | ||||
-rw-r--r-- | backend/Player.cpp | 12 | ||||
-rw-r--r-- | backend/Player.h | 1 | ||||
-rw-r--r-- | backend/String.cpp | 5 | ||||
-rw-r--r-- | backend/String.h | 1 |
5 files changed, 19 insertions, 2 deletions
diff --git a/backend/Dungeon.cpp b/backend/Dungeon.cpp index 84f9c79..fed955b 100644 --- a/backend/Dungeon.cpp +++ b/backend/Dungeon.cpp @@ -24,8 +24,8 @@ void Dungeon::update_attacks(ListRange<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); + this->player.take_damage(damage); } } 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 { diff --git a/backend/Player.h b/backend/Player.h index b101de2..0dce061 100644 --- a/backend/Player.h +++ b/backend/Player.h @@ -33,6 +33,7 @@ public: void set_location(Location &); void equip(WeaponObject *); void equip(ArmorObject *); + bool is_dead() const; private: Dungeon & dungeon; diff --git a/backend/String.cpp b/backend/String.cpp index 2f998be..381277e 100644 --- a/backend/String.cpp +++ b/backend/String.cpp @@ -15,6 +15,7 @@ String & String::operator = (const String & other) { this->set(other.data(), other.size()); return *this; } + String::String(const String & other) { this->set(other.data(), other.size()); } @@ -24,6 +25,10 @@ String::String(const char * c_str) { this->set(c_str); } +String::String(const char * data, size_t size) { + this->set(data, size); +} + String String::fmt(const char * fmt, ...) { va_list args; va_start(args, fmt); diff --git a/backend/String.h b/backend/String.h index cf4304f..0f20de6 100644 --- a/backend/String.h +++ b/backend/String.h @@ -7,6 +7,7 @@ class String { public: String(); String(const char * c_str); + String(const char * data, size_t size); String(const String &); ~String(); public: |