-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRoom.cpp
More file actions
248 lines (217 loc) · 6.57 KB
/
Copy pathRoom.cpp
File metadata and controls
248 lines (217 loc) · 6.57 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
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#include "Room.h"
#include "Command.h"
Room::Room(string description) {
this->description = description;
}
void Room::setExits(Room *north, Room *east, Room *south, Room *west) {
if (north != NULL)
exits["north"] = north;
if (east != NULL)
exits["east"] = east;
if (south != NULL)
exits["south"] = south;
if (west != NULL)
exits["west"] = west;
}
string Room::shortDescription() {
return description;
}
string Room::longDescription() {
return "room = " + description + ".\n" + displayItem() + ".\n" + displayEnemy() + ".\n" + displayNPC() + ".\n" + displayVendor() + exitString() + "\n";
}
string Room::exitString() {
string returnString = "\nexits =";
for (map<string, Room*>::iterator i = exits.begin(); i != exits.end(); i++)
// Loop through map
returnString += " " + i->first; // access the "first" element of the pair (direction as a string)
return returnString;
}
Room* Room::nextRoom(string direction) {
map<string, Room*>::iterator next = exits.find(direction); //returns an iterator for the "pair"
if (next == exits.end())
return NULL; // if exits.end() was returned, there's no room in that direction.
return next->second; // If there is a room, remove the "second" (Room*)
// part of the "pair" (<string, Room*>) and return it.
}
void Room::addItem(Item *inItem) {
//cout <<endl;
//cout << "Just added" + inItem->getLongDescription();
itemsInRoom.push_back(*inItem);
}
string Room::displayItem() {
string tempString = "items in room = ";
int sizeItems = (itemsInRoom.size());
if (itemsInRoom.size() < 1) {
tempString = "no items in room";
}
else if (itemsInRoom.size() > 0) {
int x = (0);
for (int n = sizeItems; n > 0; n--) {
tempString = tempString + itemsInRoom[x].getShortDescription() + " " ;
x++;
}
}
return tempString;
}
int Room::numberOfItems() {
return itemsInRoom.size();
}
void Room::removeItemFromRoom(int location) {
itemsInRoom.erase(itemsInRoom.begin()+location);
}
int Room::isItemInRoom(string inString)
{
int sizeItems = (itemsInRoom.size());
if (itemsInRoom.size() < 1) {
return false;
}
else if (itemsInRoom.size() > 0) {
int x = (0);
for (int n = sizeItems; n > 0; n--) {
// compare inString with short description
int tempFlag = inString.compare( itemsInRoom[x].getShortDescription());
if (tempFlag == 0) {
return x;
}
x++;
}
}
return -1;
}
void Room::addEnemy(Enemy *Enemy) {
EnemysInRoom.push_back(*Enemy);
}
string Room::showStats() {
string tempString = "Fearsome foes awaiting your blade\n";
int sizeEnemies = (EnemysInRoom.size());
if (EnemysInRoom.size() < 1) {
tempString = "All enemies have been conquered valiant warrior";
}
else if (EnemysInRoom.size() > 0) {
int x = (0);
for (int n = sizeEnemies; n > 0; n--) {
tempString = tempString + EnemysInRoom[x].showEnemyStats() + " " ;
x++;
}
}
return tempString;
}
string Room::displayEnemy() {
string tempString = "Enemies in room = ";
int sizeEnemies = (EnemysInRoom.size());
if (EnemysInRoom.size() < 1) {
tempString = "no Enemies in room";
}
else if (EnemysInRoom.size() > 0) {
int x = (0);
for (int n = sizeEnemies; n > 0; n--) {
tempString = tempString + EnemysInRoom[x].getName() + " " ;
x++;
}
}
return tempString;
}
void Room::removeEnemyFromRoom(int location) {
EnemysInRoom.erase(EnemysInRoom.begin()+location);
}
int Room::isEnemyInRoom(string inString)
{
int sizeEnemies = (EnemysInRoom.size());
if (EnemysInRoom.size() < 1) {
return false;
}
else if (EnemysInRoom.size() > 0) {
int x = (0);
for (int n = sizeEnemies; n > 0; n--) {
// compare inString with short description
int tempFlag = inString.compare( EnemysInRoom[x].getName());
if (tempFlag == 0) {
return x;
}
x++;
}
}
return -1;
}
void Room::addNPC(NPC *NPC) {
NPCSInRoom.push_back(*NPC);
}
string Room::displayNPC() {
string tempString = "NPCs in room = ";
int sizeItems = (NPCSInRoom.size());
if (NPCSInRoom.size() < 1) {
tempString = "no NPCS in room";
}
else if (NPCSInRoom.size() > 0) {
int x = (0);
for (int n = sizeItems; n > 0; n--) {
tempString = tempString + NPCSInRoom[x].getNPCName() + " " ;
x++;
}
}
return tempString;
}
int Room::isNPCInRoom(string inString)
{
int sizeItems = (NPCSInRoom.size());
if (NPCSInRoom.size() < 1) {
return -1;
}
else if (NPCSInRoom.size() > 0) {
int x = 0;
for (int n = sizeItems; n > 0; n--) {
// compare inString with short description
int tempFlag = inString.compare( NPCSInRoom[x].getNPCName());
if (tempFlag == 0) {
return x;
}
x++;
}
}
return -1;
}
void Room::addVendor(Vendor *Vendor) {
vendorsInRoom.push_back(*Vendor);
}
string Room::displayVendor() {
string tempString = "Vendors in room = ";
int sizeItems = (vendorsInRoom.size());
if ((vendorsInRoom.size() < 1)) {
tempString = "no Vendors in room";
}
else if ((vendorsInRoom.size() > 0)) {
int x = (0);
for (int n = sizeItems; n > 0; n--) {
tempString = tempString + (vendorsInRoom[x].getNPCName() + " ");
x++;
}
}
return tempString;
}
int Room::vendorPresent() {
if (vendorsInRoom.size() < 1) {
return -1;
}
else {
return 1;
}
}
int Room::isVendorInRoom(string inString)
{
int sizeItems = (vendorsInRoom.size());
if (vendorsInRoom.size() < 1) {
return -1;
}
else if (vendorsInRoom.size() > 0) {
int x = 0;
for (int n = sizeItems; n > 0; n--) {
// compare inString with short description
int tempFlag = inString.compare( vendorsInRoom[x].getNPCName());
if (tempFlag == 0) {
return x;
}
x++;
}
}
return -1;
}