CardGame
Rogue-like card videogame
Loading...
Searching...
No Matches
entity.h
Go to the documentation of this file.
1#ifndef ENTITY_H
2#define ENTITY_H
3
4#include <string>
5#include <string_view>
6
17class Entity
18{
19 public:
20 Entity() {}
21 Entity(int hp, int attack = 0, int armor = 0) : m_hp{hp}, m_attack{attack}, m_armor{armor} {}
22
24 std::string_view getName() const { return m_name; }
25
27 int getArmor() const { return m_armor; }
28
30 int getAttack() const { return m_attack; }
31
33 void resetArmor() { m_armor = 0; }
34
36 void resetAttack() { m_attack = 0; }
37
39 void increaseArmor(int amount) { m_armor += amount; }
40
42 void increaseAttack(int amount) { m_attack += amount; }
43
49 void lowerArmor(int amount)
50 {
51 m_armor -= amount;
52 if (m_armor <= 0)
53 m_armor = 0;
54 }
55
57 int getHp() const { return m_hp; }
58
60 void lowerHp(int amount) { m_hp -= amount; }
61
63 void increaseHp(int amount) { m_hp += amount; }
64
65 protected:
66 int m_hp{};
67 int m_armor{};
68 int m_attack{};
69 std::string m_name{};
70};
71
72#endif // ENTITY_H
Base class representing a combat-capable entity.
Definition: entity.h:18
void increaseArmor(int amount)
Increases armor by the given amount.
Definition: entity.h:39
void increaseAttack(int amount)
Increases attack by the given amount.
Definition: entity.h:42
std::string m_name
Definition: entity.h:69
int m_armor
Definition: entity.h:67
void lowerArmor(int amount)
Decreases armor by the given amount.
Definition: entity.h:49
void increaseHp(int amount)
Increases HP by the given amount.
Definition: entity.h:63
int getArmor() const
Returns the current armor value.
Definition: entity.h:27
int getAttack() const
Returns the current attack value.
Definition: entity.h:30
int m_hp
Definition: entity.h:66
Entity()
Definition: entity.h:20
int getHp() const
Returns the current HP value.
Definition: entity.h:57
void resetArmor()
Resets armor to zero.
Definition: entity.h:33
Entity(int hp, int attack=0, int armor=0)
Definition: entity.h:21
std::string_view getName() const
Returns the display name of the entity.
Definition: entity.h:24
void resetAttack()
Resets attack to zero.
Definition: entity.h:36
void lowerHp(int amount)
Decreases HP by the given amount.
Definition: entity.h:60
int m_attack
Definition: entity.h:68