-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfinal_battle.cpp
More file actions
230 lines (201 loc) · 7.38 KB
/
Copy pathfinal_battle.cpp
File metadata and controls
230 lines (201 loc) · 7.38 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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#include "final_battle.h"
void fb::FinalBattle::performEvent() { //auto as c++11 feature!
auto turn = 0; //Turn counter in each stage
auto pups = 0; //How many pups still alive by stage 5?
auto buff = 0; //Defense buff for Doggo
auto doom = 3; //Turns for Final Doggo to charge up his attack
while (stage != 7) { //If stage hits 7, fight is over no matter what
turn = 0;
std::cout << "\nA " << monster->getMonsterName() << " appears!\n" << std::endl;
monster->printAscii();
while (character.getCurrHP() > 0 && monster->getHP() > 0) {
if (performTurn(doom, pups, turn))
break;
}//End While
if (character.getCurrHP() < 0) {
throw std::string("You were killed by the " + monster->getMonsterName() + "!\nGAME OVER");
}
if (monster->getHP() < 0) {
isDead = true;
if (stage != 6) {
std::cout << "You successfully killed the " << monster->getMonsterName() << "!" << std::endl;
}
else {
std::cout << "Congratulations! You've exterminated the " << monster->getMonsterName() << std::endl;
throw std::string("\nYou have conquered this dungeon, hero! YOU WIN!");
}
}
std::cout << std::endl;
nextStage();
monster = getDog(stage);
std::cout << std::setfill('-') << std::setw(100) << "" << std::setfill(' ') << std::endl;
if (stage == 2) {
std::cout << "The Doggo is scared and has went into hiding. Get through his two guard Pups!" << std::endl;
std::cout << "The first Pup runs at you! Kill it in 5 turns!" << std::endl;
}
else if (stage == 3) {
std::cout << "The second Pup runs at you! Kill it in 5 turns!" << std::endl;
}
else if (stage == 4) {
std::cout << "The ScaredDoggo is driven out of hiding!" << std::endl;
}
else if (stage == 5) {
std::cout << "You've turned the ScaredDoggo into a MadDoggo..." << std::endl;
if (pups > 0) {
std::cout << "The MadDoggo chases down the deserter pups and consumes them." << std::endl;
std::cout << "MadDoggo uses " << monster->aName() << " and chows down on " << pups <<
" serving(s) of pup." << std::endl;
std::cout << "MadDoggo's defense is increased by " << pups * monster->aPower() << "." << std::endl;
buff = 20 + pups * monster->aPower();
monster->setStat(2, buff);
}
}
else if (stage == 6) {
std::cout << "The FinalDoggo is using its last resort, stop the charging of its final attack!\nNote: Sleep and Paralysis will not stop this attack!" << std::endl;
if (pups > 0) { //If the Doggo was buffed up by Consume previously
monster->setStat(2, buff);
}
}
std::cout << std::setfill('-') << std::setw(100) << "" << std::setfill(' ') << std::endl;
isVisited = true;
std::cout << std::endl << std::endl;
}
}
bool fb::FinalBattle::performTurn(int& doom, int& pups, int& turn) {
int monsterAtk;
std::string userInput;
displayCommands(turn, doom, userInput);
if (userInput == "run") {
std::cout << "You can't run away from this " << monster->getMonsterName() << "!\n" << std::endl;
return false;
}
if (userInput == "o") {
if (i.useInventory()) { //If the user used an item
performMonsterAttk(monsterAtk);
}
}
else {
int dmg;
if (userInput == "s") {
int n;
std::string input;
character.displayMoves();
bool validMove;
do {
validMove = true;
std::cout << "Which move would you like to use? ";
std::getline(std::cin, input);
if (input.length() != 1) {
validMove = false;
std::cout << "Invalid input! ";
continue;
}
try {
n = stoi(input);
dmg = character.useSpecial(n, monster);
}
catch (const std::invalid_argument& e) {
std::cout << "Invalid number! ";
validMove = false;
}
catch (const std::out_of_range& e) {
std::cout << "Invalid number! ";
validMove = false;
}
catch (...) {
std::cout << "Invalid input! ";
validMove = false;
}
} while (!validMove);
if (dmg != 0) { //0 means not enough mana
monster->takeDamage(dmg);
}
std::cout << std::endl;
}
else if (userInput == "") {
std::cout << "\nYou attack the " << monster->getMonsterName() << std::endl;
dmg = character.attack();
monster->takeDamage(dmg);
}
else {
return false;
}
if (dmg != 0) {
performMonsterAttk(monsterAtk);
}
}
turn += 1;
if ((stage == 2 || stage == 3) && monster->getHP() > 0 && turn > 5) { //If you take too long to kill a pup
pups += 1;
std::cout << "The Pup runs away!" << std::endl;
return true;
}
if (doom == 0 && monster->getHP() > 0) { //If the doom count hits 0 on the FinalDoggo
std::cout << "You have failed to stop FinalDoggo from powering up...\n";
std::cout << "FinalDoggo unleashes " << monster->aName() << ".";
character.takeDamage(monster->aPower());
throw std::string("\n\nYou were killed by the FinalDoggo! So close...\nGAME OVER");
}
std::cout << std::endl;
return false;
}
void fb::FinalBattle::displayCommands(int& turn, int& doom, std::string& userInput) {
std::cout << "Enemy HP: " << monster->getHP();
if (monster->getStatus() >= 0) {
std::cout << " Enemy Status: " << monster->getStrStatus();
}
std::cout << " Your HP: " << character.getCurrHP() << "/" << character.getHP();
std::cout << " Your Mana: " << character.getCurrMana() << "/" << character.getMana() << std::endl;
std::cout << "TURN: " << turn << std::endl << std::endl;
if (stage == 6)
{
doom -= 1;
std::cout << std::setfill('-') << std::setw(100) << "" << std::setfill(' ') << std::endl;
if (doom == 0) {
std::cout << "Kill the FinalDoggo with the next move, or you will face Armadoggen!!!\n";
}
else {
std::cout << "Gas builds up within the FinalDoggo! " << doom << " turns from destruction...\n";
}
std::cout << std::setfill('-') << std::setw(100) << "" << std::setfill(' ') << std::endl << std::endl;
}
std::cout << "--COMMANDS--\n";
std::cout << "Attack: 'enter key'\n";
std::cout << "Use special ability: 's'\n";
std::cout << "Run Away: 'run'\n";
std::cout << "Open Invntory: 'o'\n";
std::cout << "Input which command you want: ";
std::getline(std::cin, userInput);
std::transform(userInput.begin(), userInput.end(), userInput.begin(), ::tolower);
std::cout << "\n";
}
void fb::FinalBattle::performMonsterAttk(int& monsterAtk) {
if (monster->getHP() > 0) {
if (stage != 6) { //If it's FinalDoggo
monsterAtk = monster->attack();
if (monsterAtk < 0) { //I set it up so neg damage means special attack
std::cout << "The " << monster->getMonsterName() << " used " << monster->getAbilityName() << "!" << std::endl;
if (monster->getMonsterName() == "Doggo") { //Doggo's special attack
std::cout << "It gained " << monster->getAbilityPower() << " HP!\n" << std::endl;
}
else if (monster->getMonsterName() == "Pup") { //Pup's special attack
std::cout << "This Pupper is getting buffer!";
}
monsterAtk *= -1;
}
else if (monsterAtk > 0) {
std::cout << "The " << monster->getMonsterName() << " attacks!\n" << std::endl;
}
}
else
{
std::cout << "FinalDoggo's stomach is rumbling...\n";
monsterAtk = 0; // No damage to Character while charging up
}
if (monsterAtk != 0) {
if (!character.takeDamage(monsterAtk)) {
throw std::string("You were killed by the " + monster->getMonsterName() + "!\nGAME OVER");
}
}
}
}