Repository navigation
Expand file tree
/
Copy pathMap.cpp
More file actions
235 lines (182 loc) · 5.15 KB
/
Copy pathMap.cpp
File metadata and controls
235 lines (182 loc) · 5.15 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
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
#include "Descriptions.h"
#include <vector>
using namespace std;
class map {
private:
string currentLocation;
public:
map(string startLocation) {
currentLocation = startLocation;
}
string getLocation() {
return currentLocation;
}
virtual string getDescription() {
return "Default description";
}
virtual string getascii(){
return "";
}
void move() {
string destination;
cout << "Enter a location to move to: ";
cin >> destination;
currentLocation = destination;
}
};
class Hallway : public map {
private:
string name;
string hDescription;
string ascii;
public:
Hallway(string n) :map(n) {
this->name = n;
hDescription = hallwayDescriptions[rand()%5];
ascii = hallwayAscii[rand()%5];
}
string getName() {
return name;
}
string getDescription() {
return hDescription;
}
string getascii(){
return ascii;
}
};
class Forest :public map {
private:
string name;
string fDescription;
string ascii;
public:
Forest(string n) :map(n) {
this->name = n;
fDescription = forestDescriptions[rand() % 5];
ascii = forestAscii[rand()%5];
}
string getName() {
return name;
}
string getDescription() {
return fDescription;
}
string getascii(){
return ascii;
}
};
class Room : public map {
private:
string name;
string rDescription;
string ascii;
public:
Room(string n) :map(n){
this->name = n;
rDescription = roomDescriptions[rand() % 5];
ascii = roomAscii[rand() % 5];
}
string getName() {
return name;
}
string getDescription() {
return rDescription;
}
string getascii(){
return ascii;
}
};
class Patio :public map {
private:
string name;
string pDescription;
string ascii;
public:
Patio(string n) :map(n){
this->name = n;
pDescription = patioDescriptions[rand() % 4];
ascii = patioAscii[rand() % 4];
}
string getName() {
return name;
}
string getDescription() {
return pDescription;
}
string getascii(){
return ascii;
}
};
class TownSquare : public map {
private:
string name;
string tDescription;
string ascii;
public:
TownSquare(string n) :map(n) {
this-> name = n;
tDescription=townSquareDescriptions[rand() % 5];
ascii = townSquareAscii[rand() % 5];
}
string getName() {
return name;
}
string getDescription() {
return tDescription;
}
string getascii(){
return ascii;
}
};
int main() {
srand(time(0));
// Create instances of the map locations
Room room("Room");
Hallway hallway("Long hallway");
Forest forest("Sppoky forest");
Patio patio("Open sapce");
TownSquare townSquare("TownSquare");
// Set current location to room to start the game
map* currentLocation = &room;
cout << "You are currently in the " << currentLocation->getLocation()<<"."<<endl<<"If at any given time you want to move back to room just type room." << endl;
cout << "You will have to choose one of the following if you want to change location"<< endl<<endl;
cout << "hallway"<< endl;
cout << "townsquare"<<endl;
cout << "forest"<<endl;
cout << "patio"<<endl<<endl;
// Loop to move to a location on user's command
while (true) {
cout << "Enter your choice: ";
string destination;
cout << "enter a location to move to (or 'quit' to stop): ";
cin >> destination;
if (destination == "quit") {
break;
}
// Move to the desired location if it exists
if (destination == "hallway") {
currentLocation = &hallway;
} else if (destination == "forest") {
currentLocation = &forest;
} else if (destination == "patio") {
currentLocation = &patio;
} else if (destination == "townsquare") {
currentLocation = &townSquare;
}else if (destination == "room") {
currentLocation = &room;
} else {
cout << "Invalid destination." << endl;
continue;
}
// Output the description of the new location
cout << "You have moved to the " << currentLocation->getLocation() << "." << endl;
cout << currentLocation->getDescription() << endl;
cout<< currentLocation->getascii()<<endl;
}
return 0;
}