-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaRoom.cpp
More file actions
178 lines (143 loc) · 3.89 KB
/
Copy pathaRoom.cpp
File metadata and controls
178 lines (143 loc) · 3.89 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
#include "aRoom.h"
#include <iostream>
#include <string>
using namespace std;
aRoom::aRoom()
{
shortDescription = "";
longDescription = "";
}
void aRoom::setShortDescription(string rest) {
shortDescription = rest;
}
void aRoom::getShortDescription() {
cout << shortDescription;
}
void aRoom::setLongDescription(string aline) {
longDescription = aline;
}
void aRoom::getLongDescription() {
cout << longDescription << endl;
}
void aRoom::addExit(string direction, int toRoom) {
exitList.addExit(direction, toRoom);
}
int aRoom::findExit(string direction) {
return exitList.findExit(direction);
}
void aRoom::addItem(string name, string description, bool canTake) {
anItem I;
I.setName(name);
I.setDescription(description);
I.setCanTake(canTake);
itemList.addItem(I);
}
int aRoom::findItem(string name) {
return itemList.findItem(name);
}
anItem aRoom::removeItem(int index) {
return itemList.removeItem(index);
}
void aRoom::displayItems() {
itemList.displayItems();
}
void aRoom::displayExits() {
exitList.displayExits();
}
void aRoom::enter() {
cout << shortDescription << endl;
displayExits();
}
void aRoom::look() {
cout << longDescription << endl;
displayItems();
displayExits();
}
void aRoom::examine(string name, anItemList playerInventory) {
if (name.compare("") == 0) {
cout << "Examine what?" << endl;
}
bool found = false;
for (int i = 0; i < itemList.getNumItems(); i++) {
if (name.compare(itemList.getItem(i).getName()) == 0 || name.compare(playerInventory.getItem(i).getName()) == 0) {
cout << itemList.getItem(i).getDescription() << endl;
found = true;
}
}
for (int i = 0; i < itemList.getNumItems(); i++) {
if (name.compare(itemList.getItem(i).getName()) == 0 && name.compare(playerInventory.getItem(i).getName()) == 0) {
//cout << itemList.getItem(i).getDescription() << endl;
found = false;
}
}
if (found) {
cout << "There is no " << name << endl;
}
}
void aRoom::take(string name, anItemList playerInventory) {
if (name.compare("") == 0) {
cout << "Take what?" << endl;
return;
}
else {
bool found = false;
for (int i = 0; i < itemList.getNumItems(); i++) {
if (name.compare(itemList.getItem(i).getName()) == 0) {
found = true;
}
}
if (found) {
for (int i = 0; i < itemList.getNumItems(); i++) {
if (name.compare(itemList.getItem(i).getName()) == 0) {
//cout << itemList[i].getDescription() << endl;
found = true;
if (itemList.getItem(i).getCanTake() == true) {
playerInventory.addItem(itemList.getItem(i));
itemList.removeItem(i);
cout << "You take the " << name << endl;
}
if (itemList.getItem(i).getCanTake() == false) {
cout << "That item cannot be taken" << endl;
}
}
}
}
else {
cout << "There is no " << name << endl;
}
}
}
void aRoom::drop(string name, anItemList playerInventory) {
if (name.compare("") == 0) {
cout << "Drop what?" << endl;
}
else {
bool found = false;
for (int i = 0; i < playerInventory.getNumItems(); i++) {
if (name.compare(playerInventory.getItem(i).getName()) == 0) {
//cout << itemList[i].getDescription() << endl;
found = true;
}
}
if (found) {
for (int i = 0; i < playerInventory.getNumItems(); i++) {
if (name.compare(playerInventory.getItem(i).getName()) == 0) {
//cout << itemList[i].getDescription() << endl;
found = true;
itemList.addItem(playerInventory.getItem(i));
playerInventory.removeItem(i);
cout << "You drop the " << name << endl;
}
}
}
else {
cout << "You don't have a " << name << endl;
}
}
}
void aRoom::print() {
cout << "ROOM: short = " << shortDescription << endl;
cout << longDescription << endl;
itemList.print();
exitList.print();
}