-
Notifications
You must be signed in to change notification settings - Fork 0
/
potion.cc
150 lines (109 loc) · 3.92 KB
/
potion.cc
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
#include "potion.h"
#include "floor.h"
std::string Potion::usedRH = "unknown potion";
std::string Potion::usedBA = "unknown potion";
std::string Potion::usedBD = "unknown potion";
std::string Potion::usedPH = "unknown potion";
std::string Potion::usedWA = "unknown potion";
std::string Potion::usedWD = "unknown potion";
Potion::Potion(int x, int y):
GameObject(x , y, 'P') {}
Potion::~Potion() {}
// RESTORE HEALTH: Boosts up the health
RestoreHp::RestoreHp(int x, int y):
Potion(x,y) { }
std::string RestoreHp::potionType() {
return usedRH;
}
void RestoreHp::usePotion(GameObject& player, Floor *g) {
// Change string if potion used for the first time
if (usedRH == "unknown potion") usedRH = "Restore Health";
// Calculate the amount of boost in health received by a player
int diff = player.getMaxHp() - player.getHP();
int boost = 10 * player.getPotionEffect();
if((player.getRace() != "Vampire") && (boost > diff)) boost = diff;
player.setHP(player.getHP() + boost);
// Remove the potion
g->objectRemove(getx(), gety());
// Set action Message
player.setMessage("PC uses Restore Health");
}
// BOOST ATTACK: Increases the attack points
BoostAtk::BoostAtk(int x, int y):
Potion(x,y) {}
std::string BoostAtk::potionType() {
return usedBA;
}
void BoostAtk::usePotion(GameObject& player, Floor *g) {
if (usedBA == "unknown potion") usedBA = "Boost Attack";
int boost = 5 * player.getPotionEffect();
player.setAtk(player.getAtk() + boost);
// Remove the potion
g->objectRemove(getx(), gety());
// Set action Message
player.setMessage("PC uses Boost Attack");
}
// BOOST DEFENSE: Increases the defense points
BoostDef::BoostDef(int x, int y):
Potion(x,y) {}
std::string BoostDef::potionType() {
return usedBD;
}
void BoostDef::usePotion(GameObject& player, Floor *g) {
if (usedBD == "unknown potion") usedBD = "Boost Defence";
int boost = 5 * player.getPotionEffect();
player.setDef(player.getDef() + boost);
// Remove the potion
g->objectRemove(getx(), gety());
// Set action Message
player.setMessage("PC uses Boost Defence");
}
// POISON HEALTH: Decreases the health points. Cannot fall before 0.
PoisonHp::PoisonHp(int x, int y):
Potion(x,y) {}
std::string PoisonHp::potionType() {
return usedPH;
}
void PoisonHp::usePotion(GameObject& player, Floor *g) {
if (usedPH == "unknown potion") usedPH = "Poison Health";
// Calculate the amount of boost in health received by a player
int damage = 10 * player.getPotionEffect();
if ((player.getHP() - damage) < 0) damage = player.getHP();
player.setHP(player.getHP() - damage);
// Remove the potion
g->objectRemove(getx(), gety());
// Set action Message
player.setMessage("PC uses Poison Health");
}
// WOUND ATTACK: Decreases the attack points.
WoundAtk::WoundAtk(int x, int y):
Potion(x,y) {}
std::string WoundAtk::potionType() {
return usedWA;
}
void WoundAtk::usePotion(GameObject& player, Floor *g) {
if (usedWA == "unknown potion") usedWA = "Wound Attack";
int damage = 5 * player.getPotionEffect();
if ((player.getAtk() - 5) < 0) damage = player.getAtk();
player.setAtk(player.getAtk() - damage);
// Remove the potion
g->objectRemove(getx(), gety());
// Set action Message
player.setMessage("PC uses Wound Attack");
}
// WOUND DEFENSE: Decreases the defense points.
WoundDef::WoundDef(int x, int y):
Potion(x,y) {}
std::string WoundDef::potionType() {
return usedWD;
}
void WoundDef::usePotion(GameObject& player, Floor *g) {
if (usedWD == "unknown potion") usedWD = "Wound Defence";
int damage = 5 * player.getPotionEffect();
if ((player.getDef() - 5) < 0) damage = player.getDef();
player.setAtk(player.getDef() - damage);
// Remove the potion
g->objectRemove(getx(), gety());
// Set action Message
player.setMessage("PC uses Wound Defence");
}