-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTheGame.cpp
129 lines (116 loc) · 3.93 KB
/
TheGame.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
#include "TheGame.h"
TheGame::TheGame() {
commands = new CommandCenter(this);
map = new RoomManager(this);
items = new ItemManager(this);
clock = new Clock(this);
/* Setting main character to the initial room and setting flags in that room (like hasBeenVisited) */
mainCharacter = new Character(this);
mainCharacter->setLocation(map->getSpawnLocation());
commands->setMainCharacter(mainCharacter);
map->getSpawnLocation()->setVisited(true);
clock->setMainCharacter(mainCharacter);
/* Adding items to rooms */
addItemToRoom("home", "door");
addItemToRoom("home", "leaflet");
// Adding items to night maze dungeon
addItemToRoom("night_maze_landing", "potion 1");
addItemToRoom("night_maze_landing", "flag 1");
addItemToRoom("night_maze_landing", "flag 2");
addItemToRoom("night_maze_landing", "flag 3");
addItemToRoom("night_maze_landing", "flag 4");
addItemToRoom("night_maze_landing", "flag 5");
addItemToRoom("maze6", "potion 2");
addItemToRoom("night_maze_pedestal", "ice key");
addItemToRoom("night_maze_pedestal", "potion 3");
/* Adding locks to paths */
addLockToPath("home", "north", "ice key", "door", "The door is locked with a silver-ringed keyhole.", "You hear a soft click.");
/* Printing room description */
cout << "***Try typing \"help\" to get you started." << endl << endl;
commands->doCommand("look");
}
Character* TheGame::getMainCharacter() {
return mainCharacter;
}
ItemManager* TheGame::getItems() {
return items;
}
RoomManager* TheGame::getMap() {
return map;
}
Clock* TheGame::getClock() {
return clock;
}
bool TheGame::over() {
return commands->over();
}
void TheGame::doCommand(string command) {
commands->doCommand(command);
}
void TheGame::addItemToRoom(string room, string item) {
Item* itemToAdd = items->findItem(item);
Room* destination = map->findRoom(room);
if (itemToAdd && destination) {
destination->addItem(itemToAdd);
}
else {
std::cout << "COULD NOT ADD " + item + " TO " + room + ". Please fix!" << std::endl;
}
return;
}
void TheGame::addLockToPath(string room, string direction, string key, string lock, string lockMessage, string unlockMessage) {
Room* pathLocation = nullptr;
Path* path = nullptr;
Item* pairKey = nullptr;
Item* pairLock = nullptr;
pathLocation = map->findRoom(room);
if (pathLocation) {
path = pathLocation->getPath(direction);
if (path) {
pairKey = items->findItem(key);
if (pairKey) {
pairLock = items->findItem(lock);
if (pairLock)
items->addKeyLockPair(path, pairKey, pairLock, lockMessage, unlockMessage);
else
cout << "addLockToPath() failed. Could not find lock (" << lock << ") to add." << endl;
}
else
cout << "addLockToPath() failed. Could not find key (" << key << ") to add." << endl;
}
else
cout << "addLockToPath() failed. Could not find path (" << direction << ") within room (" << room << ")." << endl;
}
else
cout << "addLockToPath() failed. Could not find room (" << room << ")." << endl;
return;
}
/*
void TheGame::addLockToPath(string room, string direction, string lock, string errorMessage) {
KeyLockPair* locker = nullptr;
locker = items->findPair(lock);
Room* tempRoom = nullptr;
tempRoom = map->findRoom(room);
Path* path = nullptr;
if (tempRoom)
path = tempRoom->getPath(direction);
else {
cout << "BUG. Could not find room to add path to. ROOM: "<< room << endl;
return;
}
if (path)
if (locker) {
locker->path = path;
locker->lockMessage = errorMessage;
path->setBarrier(errorMessage);
}
else {
cout << "BUG. Tried to add a non-existent lock to a path. LOCK: " << lock << std::endl;
return;
}
else {
cout << "BUG. Could not find the path inside room." << endl;
}
return;
}
*/