-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcharacter.cpp
More file actions
195 lines (153 loc) · 4.13 KB
/
Copy pathcharacter.cpp
File metadata and controls
195 lines (153 loc) · 4.13 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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#include "character.h"
Character::Character() : stats(NumberOfStats), xCoor(0), yCoor(0), currentFloor(0), money(0) {
stats[HP] = stats[currHP] = 25;
stats[Mana] = stats[currMana] = 15;
stats[ATK] = 10;
stats[DEF] = 12;
moves.push_back(new Moves::ParalyzingShock);
moves.push_back(new Moves::ToxicStar);
moves.push_back(new Moves::ForbiddenChant);
}
Character::~Character() {
for (unsigned i = 0; i < moves.size(); i++)
delete moves[i];
}
void Character::displayMoves() {
for (unsigned i = 0, j = 1; i < moves.size(); i++) {
std::cout << j++ << ". " << *moves[i] << std::endl;
}
}
int Character::useSpecial(int num, Monster* m) {
int i = num - 1; //i is index in vector that has move
if (!moves.at(i)->getCanUse()) {
std::cout << "\nThis ability is locked! Find a scroll to unlock it.\n" << std::endl;
return 0;
}
//Deal with Mana cost
if (moves[i]->getManaCost() > stats[currMana]) {
std::cout << "Not enough mana!" << std::endl;
return 0;
}
stats[currMana] -= moves[i]->getManaCost();
//Then with status
if (m->getStatus() < 0) { //greater than 0 means it has a status effect already
m->setStatus(moves[i]->getStatusEffect());
}
//Then with damage
return moves[i]->getDamage() + stats[ATK];
}
void Character::setCoor(int newX, int newY) {
xCoor = newX;
yCoor = newY;
}
int Character::getX() const {
return xCoor;
}
int Character::getY() const {
return yCoor;
}
std::string Character::getName() const {
return name;
}
void Character::addMoney(int m) {
money += m;
}
int Character::getMoney() const {
return money;
}
void Character::setHP(int h) {
stats[HP] = h;
}
bool Character::unlockRandomAbility() {
int count = 0;
for (std::vector<SpecialMove*>::iterator i = moves.begin(); i != moves.end(); i++) {
if ((*i)->getCanUse())
count++;
}
if (count == 3) {
std::cout << "\nThe scroll lights up, but nothing seems to happen. Perhaps you've learned all the abilities?\n" << std::endl;
return false;//no more moves to unlock
}
int r;
do {
r = rand() % 3;
} while (moves[r]->getCanUse());
moves[r]->setCanUse(true);
std::cout << "\nThe scroll lights up and you gain its knowledge!\nYou now know: " << moves[r]->getMoveName() << "!\n" << std::endl;
return true;
}
void Character::setCurrHP(int h) {
int amt = stats[currHP] + h;
if (amt > stats[HP])
amt = stats[HP];
stats[currHP] = amt;
}
void Character::setCurrMana(int m) {
int amt = stats[currMana] + m;
if (amt > stats[Mana])
amt = stats[Mana];
stats[currMana] = amt;
}
void Character::setMana(int m) {
stats[Mana] = m;
}
void Character::setATK(int a) {
stats[ATK] = a;
}
void Character::setDEF(int d) {
stats[DEF] = d;
}
void Character::setTurns(int t) {
turns = t;
}
//Stat Accessors
int Character::getHP() const {
return stats[HP];
}
int Character::getCurrHP() const {
return stats[currHP];
}
int Character::getMana() const {
return stats[Mana];
}
int Character::getCurrMana() const {
return stats[currMana];
}
int Character::getATK() const {
return stats[ATK];
}
int Character::getDEF() const {
return stats[DEF];
}
int Character::getTurns() const {
return turns;
}
int Character::attack() const {
return stats[ATK];
}
//This function will return TRUE if character is still alive and FALSE if not
bool Character::takeDamage(int dmg) {
int reducedDmg = dmg - stats[DEF];
reducedDmg = reducedDmg <= 0 ? 1 : reducedDmg;
stats[currHP] -= (reducedDmg);
return stats[currHP] <= 0 ? false : true;
}
void Character::setCurrentFloor(int f) {
if (f < 0 || f > 9)
return;
currentFloor = f;
}
int Character::getCurrentFloor() const {
return currentFloor;
}
void Character::moveToNextFloor() {
currentFloor++;
}
std::ostream& operator << (std::ostream& out, const Character& c) {
out << "HP: " << c.stats[c.currHP] << "/" << c.stats[c.HP];
out << " | Mana: " << c.stats[c.currMana] << "/" << c.stats[c.Mana];
out << " | ATK: " << c.stats[c.ATK];
out << " | DEF: " << c.stats[c.DEF];
out << " | Gold: " << c.money;
return out;
}