-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMonster.cpp
More file actions
263 lines (263 loc) · 11.6 KB
/
Monster.cpp
File metadata and controls
263 lines (263 loc) · 11.6 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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
#include "Monster.h"
Monster::Monster():GameCharacter(){}
Monster::Monster(string name,int health,int attack,int defense):GameCharacter(name,"Monster",health,attack,defense){
}
bool Monster::triggerEvent(Object* add){
Player* battle = static_cast<Player*> (add);
cout<<"Health:"<<getCurrentHealth()<<"/"<<getMaxHealth()<<"\nAttack:"<<getAttack()<<"\nDefense"<<getDefense()<<endl;
cout<<"What's Your Decision?"<<endl;
string decision;
cout<<"A.Battle!!\n"<<"B.Retreat\n"<<"C.Sleep\n"<<"D.Use Attack potion"<<endl;
cin>>decision;
while(decision != "A" && decision != "B" && decision != "C" && decision != "D"){
cout<<"Enter Appropriate Decision!!!"<<endl;
}
if(decision == "A"){
int z = 1;
for(auto i : battle->getSkill()){
if(i == "Kill piggie"){
z = 0;
break;
}
}
if(z == 0){
srand( time(NULL) );
int x = rand() % 100;
if(x > 49){
this -> setCurrentHealth(0);
cout<<"003:You killed that fat Tung\n";
}
else{
battle->setCurrentHealth(0);
cout<<"Oh NO!!!\nSkill Active fail!!!";
}
}
while(1){
if(getCurrentHealth() <= 0){
return true;
}
if(battle->getCurrentHealth() <= 0){
int u = 1;
for(auto i:battle->getSkill()){
if(i == "Lock Down"){
u = 0;
break;
}
}
if(u == 0){
cout<<"You active skill Lock Down\nYour health is now full\n";
battle->setCurrentHealth(battle->getMaxHealth());
}
else{
return false;
}
}
if(battle -> getSkill().empty() != true && battle-> getcd() == 0){
cout<<"Do you want to active your skill?"<<endl;
cout<<"YES or NO Make Your Decision"<<endl;
string x;
cin>>x;
while(x != "YES" && x != "NO"){
cout<<"Please Enter YES or NO!!!"<<endl;
cin>>x;
}
if(x == "YES"){
cout<<"Which Skill you want to active"<<endl;
vector<string> s = battle->getSkill();
int l = 1;
for(int i = 0;i < s.size();i++){
if(s[i] != "Lock Down"){
cout<<l<<". "<<s[i]<<endl;
l++;
}
}
int y;
cin>>y;
if(y == 1){
int h = this -> getMaxHealth() / 4;
h = getCurrentHealth() - h;
this -> setCurrentHealth(h);
}
else if(y == 2){
battle->increaseStates(0,10,0);
this -> takeDamage(30);
}
cout<<getName()<<"\nHealth"<<getCurrentHealth()<<"/"<<getMaxHealth()<<endl;
cout<<"Your Health:"<<battle->getCurrentHealth()<<"/"<<battle -> getMaxHealth()<<"\nYour Attack:"<<battle->getAttack()<<endl;
battle->setcd(3);
cout<<"Your skill cd :"<<battle->getcd()<<endl;
continue;
}
else if(x =="NO"){
cout<<"You keep your power"<<endl;
this -> takeDamage(battle->getAttack());
if(this -> getCurrentHealth() <= 0){
cout<<"You Beat The "<<getName()<<endl;
return true;
}
battle->takeDamage(this -> getAttack());
cout<<getName()<<"\nHealth"<<getCurrentHealth()<<"/"<<getMaxHealth()<<endl;
cout<<"Your Health:"<<battle->getCurrentHealth()<<"/"<<battle -> getMaxHealth()<<"\nYour Attack:"<<battle->getAttack()<<endl;
if(battle->getCurrentHealth() <= 0){
int u = 1;
for(auto i:battle->getSkill()){
if(i == "Lock Down"){
u = 0;
i.erase(i.end());
break;
}
}
if(u == 0){
cout<<"You active skill Lock Down\nYour health is now full\n";
battle->setCurrentHealth(battle->getMaxHealth());
}
else{
return false;
}
}
string keep;
cout<<"What's next?\n"<<"A.Keep Fighting!!!\n"<<"B.Retreat....\n"<<"C.Use Attack Potion"<<endl;
cin>>keep;
while(keep != "A" && keep != "B" && keep != "C"){
cout<<"Enter Appropriate Decision!!!"<<endl;
cin>>keep;
}
if(keep == "B"){
cout<<"You have moved to Room:"<<battle->getPreviousRoom()->getIndex()<<endl;
battle->changeRoom(battle->getPreviousRoom());
return true;
}
else if(keep == "C"){
cout<<"Which potion you want to use?"<<endl;
vector<Item>poision;
for(i:battle->getBackpack()){
if(i.getTag() == "attack potion"){
poision.push_back(i);
}
}
if(poision.empty() == true){
cout<<"You got nothing to use"<<endl;
}
else{
int x = 1;
for(int i = 0;i < poision.size();i++){
cout<<x<<"."<<poision[i].getName()<<endl;
x++;
}
}
}
if(battle->getcd() >= 0){
battle->decreasecd();
}
cout<<"Remain turns to use skills: "<<battle->getcd()<<endl;
}
}
else{
this -> takeDamage(battle->getAttack());
if(this -> getCurrentHealth() <= 0){
cout<<"You Beat The "<<getName()<<endl;
return true;
}
battle->takeDamage(this -> getAttack());
cout<<getName()<<"\nHealth"<<getCurrentHealth()<<"/"<<getMaxHealth()<<endl;
cout<<"Your Health:"<<battle->getCurrentHealth()<<"/"<<battle -> getMaxHealth()<<"\nYour Attack:"<<battle->getAttack()<<endl;
if(battle->getCurrentHealth() <= 0){
int u = 1;
for(auto i:battle->getSkill()){
if(i == "Lock Down"){
u = 0;
i.erase(i.end());
break;
}
}
if(u == 0){
cout<<"You active skill Lock Down\nYour health is now full\n";
battle->setCurrentHealth(battle->getMaxHealth());
}
else{
return false;
}
}
string keep;
cout<<"What's next?\n"<<"A.Keep Fighting!!!\n"<<"B.Retreat....\n"<<"C.Use Attack Potion"<<endl;
cin>>keep;
while(keep != "A" && keep != "B" && keep != "C"){
cout<<"Enter Appropriate Decision!!!"<<endl;
cin>>keep;
}
if(keep == "B"){
cout<<"You have moved to Room:"<<battle->getPreviousRoom()->getIndex()<<endl;
battle->changeRoom(battle->getPreviousRoom());
return true;
}
else if(keep == "C"){
cout<<"Which potion you want to use?"<<endl;
vector<Item> posi = battle->getBackpack();
int o = 1;
for(int i = 0;i < posi.size();i++){
if(posi[i].getTag() == "attackpotion"){
int j = i + 1;
cout<<j<<". "<<posi[i].getName()<<endl;
o = 0;
}
}
if(o == 1){
cout<<"You have nothing to use!!!\n";
return true;
}
else{
cout<<"Enter your decision\n";
int w;
cin>>w;
w--;
this->takeDamage(this -> getDefense() + battle->getBackpack()[w].getAttack());
battle->eraback(w);
cout<<getName()<<"\nHealth"<<getCurrentHealth()<<"/"<<getMaxHealth()<<endl;
cout<<"Your Health:"<<battle->getCurrentHealth()<<"/"<<battle -> getMaxHealth()<<"\nYour Attack:"<<battle->getAttack()<<endl;
return true;
}
}
battle->decreasecd();
cout<<"Remain turns to use skills: "<<battle->getcd()<<endl;
}
}
}
else if(decision == "B"){
cout<<"You Flee To The Room:"<<battle->getPreviousRoom()->getIndex()<<"You Coward XD"<<endl;
battle->changeRoom(battle->getPreviousRoom());
return true;
}
else if(decision == "C"){
cout<<"You got hit by the monster!!!"<<endl;
battle->takeDamage(this -> getAttack());
cout<<"Your current health:"<<battle->getCurrentHealth()<<endl;
return true;
}
else if(decision == "D"){
cout<<"Which potion you want to use?"<<endl;
vector<Item> posi = battle->getBackpack();
int o = 1;
for(int i = 0;i < posi.size();i++){
if(posi[i].getTag() == "attackpotion"){
int j = i + 1;
cout<<j<<". "<<posi[i].getName()<<endl;
o = 0;
}
}
if(o == 1){
cout<<"You have nothing to use!!!\n";
return true;
}
else{
cout<<"Enter your decision\n";
int w;
cin>>w;
w--;
this->takeDamage(this -> getDefense() + battle->getBackpack()[w].getAttack());
battle->eraback(w);
cout<<getName()<<"\nHealth"<<getCurrentHealth()<<"/"<<getMaxHealth()<<endl;
cout<<"Your Health:"<<battle->getCurrentHealth()<<"/"<<battle -> getMaxHealth()<<"\nYour Attack:"<<battle->getAttack()<<endl;
return true;
}
}
}