-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEntity.cpp
More file actions
163 lines (140 loc) · 3.53 KB
/
Entity.cpp
File metadata and controls
163 lines (140 loc) · 3.53 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#ifndef ENTITY_C
#define ENTITY_C
#include <iostream>
class Entity {
private:
std::string name;
// HP
int maxHP, HP, baseHP;
// MP
int maxMP, MP;
// DMG
int baseDMG, DMG;
// Def
int baseDef, Def;
int level, experience, gold;
public:
Entity() {
this->name = "Player";
this->maxHP = this->baseHP = 0;
this->HP = 0;
this->maxMP = 0;
this->MP = 0;
this->baseDMG = 0;
this->DMG = 0;
this->baseDef = 0;
this->Def = 0;
this->level = 1;
this->experience = 0;
this->gold = 0;
}
Entity(std::string name,int HP, int MP, int baseDMG, int baseDef) {
this->name = name;
this->maxHP = this->HP = this->baseHP = HP;
this->maxMP = this->MP = MP;
this->baseDMG = this->DMG = baseDMG;
this->baseDef = this->Def = baseDef;
this->level = 1;
this->experience = 0;
this->gold = 0;
}
void showStats() const {
std::cout << std::endl;
std::cout << "=========" << this->name << "'s stats ==========\n";
std::cout << "HP: " << HP << "\n";
std::cout << "MP: " << MP << "\n";
std::cout << "Level: " << level << "\n";
std::cout << "DMG: " << DMG << "\n";
std::cout << "Def: " << Def << "\n";
}
// ============= NAME ===========
std::string getName() const { return name; }
// ============= GOLD ===========
int getGold() const {return gold;}
void updateGold(int gold, bool adding = true) {
if (adding) {
this->gold += gold;
std::cout << "You received " << gold << " gold\n";
}
else {
this->gold -= gold;
if (this->gold < 0) this->gold = 0;
std::cout << "You lost " << gold << " gold\n";
}
}
// ============= EXPERIENCE ===========
int getExperience() const {return experience;}
void addExperience(int experience) {
this->experience += experience;
std::cout << "You received " << experience << " experience\n";
}
// ============= HP ===========
int getMaxHP() const {return maxHP;}
int getHP() const { return HP;}
void updateHP(int hp, bool adding = true) {
if (adding) {
this->HP += HP;
std::cout << "You received " << HP << " HP\n";
}
else {
this->HP -= HP;
if (this->HP < 0) this->HP = 0;
std::cout << "You lost " << HP << " HP\n";
}
}
// ============= MP ===========
int getMaxMP() const { return this->maxMP; }
int getMP() const {return MP;}
void updateMP(int MP, bool adding = true) {
if (adding) {
this->MP += MP;
std::cout << "You received " << MP << " MP\n";
}
else {
this->MP -= MP;
if (this->MP < 0) this->MP = 0;
std::cout << "You lost " << MP << " MP\n";
}
}
// ============= DMG ===========
int getDMG() const {return DMG;}
void updateDMG(int DMG, bool adding=true) {
if (adding) {
this->DMG += DMG;
std::cout << "You received " << DMG << " DMG\n";
}
else {
this->DMG -= DMG;
std::cout << "You lost " << DMG << " DMG\n";
}
}
void doDMG(Entity* entity) const {entity->dealsDamage(this->DMG);}
// ============= Def ===========
int getDef() const {return Def;}
void updateDef(int def, bool add = true) {
if (add) {
this->Def += Def;
std::cout << "You received " << Def << " Def\n";
}
else {
this->Def -= Def;
std::cout << "You lost " << Def << " Def\n";
}
}
void dealsDamage(int damage) {
if (this->HP + this->Def <= damage) {
this->HP = 0;
}
else {
this->HP -= (damage - Def) > 0 ? (damage - Def) : 0;
}
std::cout << this->name << " received " << damage << " damage\n";
}
// ============= LEVEL ===========
int getLevel() const {return level;}
void addLevel(int level) {
this->level += level;
std::cout << "You received " << level << " level\n";
}
};
#endif // !ENTITY_C