-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.cpp
More file actions
80 lines (69 loc) · 1.25 KB
/
Player.cpp
File metadata and controls
80 lines (69 loc) · 1.25 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
#include "Player.hpp"
Player::Player(std::string name) : Character(name, 500, 50, 50, 50)
{
}
bool Player::addItem(Item* item)
{
if(item)
{
this->itemInventory.push_back(item);
std::cout << item->getName() << " added to inventory. ";
std::cout << item->getDescription() << std::endl;
return true;
}
else
{
std::cout << "No item to add." << std::endl;
return false;
}
}
Item* Player::removeItem(std::string name)
{
bool found = false;
Item* item;
for(int x = 0; x < itemInventory.size(); x++)
{
if(itemInventory[x]->getName() == name)
{
item = itemInventory[x];
itemInventory.erase(itemInventory.begin()+x);
found = true;
break;
}
}
if(found)
{
return item;
}
else
{
std::cout << "Item not found in inventory." << std::endl;
return NULL;
}
}
std::string Player::update()
{
std::string str_userInput;
std::cout << std::endl << ">> ";
getline(std::cin, str_userInput);
return str_userInput;
}
void Player::executeAttack()
{
this->attack(target, 20);
}
void Player::printInventory()
{
if(itemInventory.empty())
{
std::cout << "Inventory is empty." << std::endl;
}
else
{
std::cout << "Inventory:" << std::endl;
for(Item* item : itemInventory)
{
std::cout << item->getName() << std::endl;
}
}
}