-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMonster.cpp
61 lines (50 loc) · 2.66 KB
/
Monster.cpp
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
#include "Monster.h"
Monster::Monster(){}
Monster::Monster(string name, int currentHealth, int attack, int defense):GameCharacter(name,"Monster",currentHealth,attack,defense){
}
void Monster::triggerEvent(Object* player,Object* monster){
Player* playerr = dynamic_cast<Player*>(player);
Monster* monsterr = dynamic_cast<Monster*>(monster);
char c;
bool flag = true;
cout << "Choose action:" << endl;
cout << "A.Attack" << endl;
cout << "B.Retreat" << endl;
cin >> c;
while(monsterr->getCurrentHealth()>0 && playerr->getCurrentHealth()>0 && flag==true){
switch(c){
case 'a': case 'A': cout << "You choose to attack" << endl;
cout << "Your attack does " << playerr->getAttack() << " damage" << endl;
monsterr->takeDamage(playerr->getAttack());
if(monsterr->checkIsDead()){
cout << "You beat the " << monsterr->getName() << endl;
if(monsterr->getName()!="boss"){
cout << monsterr->getName() <<" drops a crystal" << endl;
playerr->setCrystal(playerr->getCrystal()+1);
}
}
else{
cout << "Now the " << monsterr->getName() << " have " << monsterr->getCurrentHealth() << " health" << endl;
cout << "The " << monsterr->getName() << "'s attack does " << monsterr->getAttack() << " damage" << endl;
playerr->takeDamage(monsterr->getAttack());
if(playerr->checkIsDead()){
cout << "You dead" << endl;
exit(0);
}
else{
cout << "Now you have " << playerr->getCurrentHealth() << " health" << endl;
cout << endl;
cout << "Choose action:" << endl;
cout << "A.Attack" << endl;
cout << "B.Retreat" << endl;
cin >> c;
cout << endl;
}
}
break;
case 'b': case 'B': playerr->changeRoom(playerr->getPreviousRoom());
flag = false;
break;
}
}
}