-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.cpp
113 lines (98 loc) · 1.89 KB
/
Player.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
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
#include <string>
#include <iostream>
#include "Player.hpp"
#include "Space.hpp"
#include <vector>
#include <algorithm>
Player::Player()
{
//steps = 0;
healthPoints = 20;
inventoryCapacity = 6;
finish = false;
}
Player::~Player()
{
}
void Player::setLocation(Space* current_location)
{
location = current_location;
}
Space* Player::getLocation()
{
return location;
}
void Player::setHealthPoints(int health)
{
healthPoints = health;
}
int Player::getHealthPoints()
{
return healthPoints;
}
bool Player::checkAlive()
{
if (getHealthPoints() > 0)
{
return true;
}
else
{
return false;
}
}
void Player::removeItem(std::string item)
{
//https://stackoverflow.com/questions/9121532/delete-strings-in-a-vector
for (int i = 0; i < inventory.size(); i++)
{
if (inventory.at(i) == item)
{
inventory.erase(inventory.begin() + i);
}
}
}
//inventory functions
void Player::addItem(std::string item)
{
if (inventory.size() > inventoryCapacity)
{
std::cout << "You can not carry any more items." << std::endl;
}
else
{
std::cout << "You have added the " << item << " to your inventory." << std::endl;
inventory.push_back(item);
}
}
void Player::printInventory()
{
if (inventory.size() == 0)
{
std::cout << "You do not have any items in your inventory." << std::endl;
}
else
{
std::cout << "Inventory: " << std::endl;
for (int i = 0; i < inventory.size(); i++)
{
std::cout << "item #" << i + 1 << ": " << inventory.at(i) << " " << std::endl;
}
}
}
bool Player::checkFinish()
{
return finish;
}
bool Player::checkItem(std::string item)
{
//https://stackoverflow.com/questions/6277646/in-c-check-if-stdvectorstring-contains-a-certain-value
if (std::find(inventory.begin(), inventory.end(), item) != inventory.end())
{
return true;
}
else
{
return false;
}
}