-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCharacter.cpp
213 lines (188 loc) · 7.14 KB
/
Character.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
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
//
// Created by Justin Lin on 2019-06-03.
//
/*********************************************************************
** Program name: Character.cpp
** Author: Justin Lin
** Date: 06/03/2019
** Description: This is the implementation file for the Character class. It
* has as member variables two ints representing hp
* and number of items. It has a string array with a max
* size of 5 representing the inventory of a Character.
* There are also 5 bools representing flags to indicate
* if the player has a certain key item. There is a Ctor
* that sets the starting values of each of the member variables.
* The player starts with 10hp, and 1 item (a pencil), and the
* bools are set to false. There are setters/getters for the hp
* and getters for the bool variables. There is a takeItem
* method that takes in as an argument a string and adds the item
* to the player inventory. There is a removeItem method that
* takes as an argument a string and removes the item from the
* player's inventory. There is a checkItem method that will
* loop through the player's inventory and set the flags based
* upon the items in inventory. Lastly there is a method to
* print the inventory and the player's stats.
*********************************************************************/
#include "Character.hpp"
#include <iostream>
#include <string>
using std::cout;
using std::endl;
using std::string;
/*******************************************************************************
Name: Justin Lin
Called by: N/A
Calls: N/A
Passed: N/A
Returns: N/A
Description: This is the default constructor for the Character class. The
constructor sets starting hp to 10, number of items to 1,
initializes the item array to contain a Pencil, and all the bool
values to false.
*******************************************************************************/
Character::Character() : hp(10), numItems(1), items{"Pencil", "", "", "", ""},
hasKey(false), hasCrowbar(false), hasUniform(false),
hasCarrot(false) {}
// Setter for hp
void Character::setHP(int hp) {
this->hp = hp;
}
// Getter for hp
int Character::getHP() {
return hp;
}
// Getter for key
bool Character::getKey() {
return hasKey;
}
// Getter for crowbar
bool Character::getCrowbar() {
return hasCrowbar;
}
// Getter for uniform
bool Character::getUniform(){
return hasUniform;
}
// Getter for carrot
bool Character::getCarrot() {
return hasCarrot;
}
// Getter for fake mustache
bool Character::getMustache() {
return hasMustache;
}
/*******************************************************************************
Name: Justin Lin
Called by: Dining::interactions, Stable::interactions, Cell::interactions,
Cargo::interactions
Calls: N/A
Passed: string
Returns: N/A
Description: This method allows the user to pick up an item and add it to
their inventory. If the inventory is full, the method will print
an error message letting the user know their inventory is full.
It takes in a string representing the item name as an argument
and adds it to the items array.
*******************************************************************************/
// Pick up item
void Character::takeItem(string item) {
// If player has space add item to inventory
if (numItems < 5) {
items[numItems] = item;
numItems++;
// Player inventory is max
} else {
cout << "You think you can fit that in your pockets? Drop something!"
<< endl;
}
}
/*******************************************************************************
Name: Justin Lin
Called by: Dining::interactions, Stable::interactions, Cell::interactions,
Cell::openCell, Cargo::interactions, Dining::mustache
Calls: N/A
Passed: N/A
Returns: N/A
Description: This method checks the user's inventory for key items in the game
and sets the respective bool flags to true if the player has the
item.
*******************************************************************************/
// Checks player's inventory for key items
void Character::checkItems() {
for (int i = 0; i < numItems; i++) {
if (items[i] == "Cell Key") {
hasKey = true;
}
if (items[i] == "Crowbar") {
hasCrowbar = true;
}
if (items[i] == "Guard Uniform") {
hasUniform = true;
}
if (items[i] == "Carrot") {
hasCarrot = true;
}
if (items[i] == "Fake mustache") {
hasMustache = true;
}
}
}
/*******************************************************************************
Name: Justin Lin
Called by: Cell::interactions(), Cell::openCell(), Dining::mustache
Calls: N/A
Passed: string
Returns: N/A
Description: This method takes in a string argument representing the item name
that is to be removed and removes it from the player's inventory
if it exists. Then, it will shift the remaining items in the
array over so there is not a gap in the array.
*******************************************************************************/
void Character::removeItem(string item) {
for (int i = 0; i < numItems; i++) {
if (items[i] == item) {
items[i] = "";
numItems--;
// Moves remaining items over
for (i; i < numItems; i++) {
items[i] = items[i+1];
}
}
}
}
/*******************************************************************************
Name: Justin Lin
Called by: interactions()
Calls: N/A
Passed: N/A
Returns: N/A
Description: This method prints the contents of the player's inventory to the
screen.
*******************************************************************************/
// Prints contents of player's inventory
void Character::inventory() {
cout << "[Inventory " << numItems << "/5]" << endl;
for (int i = 0; i < numItems; i++) {
cout << " " << i+1 << ". " << items[i] << endl;
}
cout << endl;
}
/*******************************************************************************
Name: Justin Lin
Called by: interactions()
Calls: N/A
Passed: N/A
Returns: N/A
Description: This method prints the player's hp to the screen showing the user
how many moves (hp) is left. Hp is represented by hearts.
*******************************************************************************/
// Prints stats represented by unicode symbols
void Character::stats() {
cout << "[Stats]" << endl;
// Unicode symbol for hearts to represent hp
cout << " Health: ";
for (int i = 0; i < hp; i++) {
cout << "\u2665 ";
}
cout << "\n" << endl;
}