-
Notifications
You must be signed in to change notification settings - Fork 0
/
combatunit.cpp
68 lines (61 loc) · 1.82 KB
/
combatunit.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
62
63
64
65
66
67
68
#include "combatunit.hpp"
CombatUnit::CombatUnit() {
}
CombatUnit::CombatUnit(std::string newName, int newHealth) {
health = newHealth;
name = newName;
}
void CombatUnit::modifyHealth(int displacement, CombatUnit* target) {
name = target->getName();
health = health + displacement;
if(target->getHealth()<1 && target->getName() =="You")
{
std::cout<<"You have fallen :(\n";
return;
}
else {
if (name == "You") {
std::cout << name << " have " << health << " health left\n";
} else {
std::cout << name << " has " << health << " health left\n";
}
}
}
int CombatUnit::getHealth() {
return health;
}
void CombatUnit::showInventory() {
for(int i=0; i<inventory.size(); i++){
if(inventory.at(i)->getType()!="Potion") {
std::cout << inventory.at(i)->getName() << "\n";
}
}
}
std::string CombatUnit::getName() {
return name;
}
//Make virtual, rewrite without prompts in enemy class
void CombatUnit::attack(CombatUnit* target) {
std::string weaponName;
bool found = false;
while (!found) {
std::cout << "which weapon? (type 'Check' to look at inventory) \n";
getline(std::cin, weaponName);
if(weaponName == "Check")
{
this->showInventory();
}
else
{
for (int i = 0; i < inventory.size(); i++) {
if (inventory.at(i)->getName() == weaponName) {
target->modifyHealth(-((Weapon*) inventory.at(i))->getDamage(), target);
found = true;
}
}
if (!found) {
std::cout << "Item not found, check spelling or lookup inventory \n";
}
}
}
}