-
Notifications
You must be signed in to change notification settings - Fork 0
/
Playfield.cpp
executable file
·192 lines (162 loc) · 6.22 KB
/
Playfield.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
#include "Playfield.h"
Playfield* Playfield::pinstance = 0;// initialize pointer
Playfield* Playfield::Instance ()
{
if (pinstance == 0) // is it the first call?
{
pinstance = new Playfield; // create sole instance
}
return pinstance; // address of sole instance
}
Playfield::Playfield()
{
create();
}
void Playfield::create()
{
// create player
setPlayer("ceiling cat");
// create rooms;
//first floor
Room * frontyard = addRoom("front yard", "outside the main house, where the trees are", "img/frontyard.png");
Room * backyard = addRoom("back yard", "outside, behind the house. There is pond out here", "img/backyard.png");
Room * gardenhouse = addRoom("garden house", "the small wooden building in the back yard", "img/gardenshed.png");
Room * garage = addRoom("garage", "where the car sleeps", "img/garage.png");
Room * hallway = addRoom("hallway", "where you enter the house", "img/hallway.png");
Room * livingroom = addRoom("living room", "where we live", "img/livingroom.png");
Room * kitchen = addRoom("kitchen", "where the munchies are made", "img/kitchen.png");
Room * storage = addRoom("storage room", "where the munchies are stored", "img/storage.png");
Room * veranda = addRoom("veranda", "between the kitchen and the back yard", "img/veranda.png");
//second floor
Room * bathroom = addRoom("bath room", "where the girls spent most of their time", "img/bathroom.png");
Room * landing = addRoom("landing", "the space to go from one room to the other", "img/landing.png");
Room * guestroom = addRoom("guest room", "where the guests sleep", "img/guestroom.png");
Room * bedroom = addRoom("bed room", "where you sleep", "img/bedroom.png");
Room * balcony = addRoom("balcony", "where you go get some air", "img/balcony.png");
//attic
Room * frontattic = addRoom("front side of the attic", "where they keep the garbage", "img/frontattic.png");
Room * backattic = addRoom("hidden back side of the attic", "where they hide stuff", "img/backattic.png");
Room * vault = addRoom("vault", "where you win", "img/vault.png");
//add stuff to rooms
Item * kitchenkey = addItemToRoom("kitchen key", balcony);
Item * garagekey = addItemToRoom("garage key", vault);
Item * bedroomkey = addItemToRoom("bedroom key", vault);
Item * elevatorbutton = addItemToRoom("elevator button", garage);
Item * bathroomkey = addItemToRoom("key to the bathroom", guestroom);
Item * ladder = addItemToRoom("strong ladder", storage);
Item * drill = addItemToRoom("heavy looking drill", garage);
Item * mainkey = addItemToRoom("key to the house", gardenhouse);
Item * table = addItemToRoom("table", frontyard);
Item * rubiks_cube = addItemToRoom("rubiks cube", garage);
Item * horse = addItemToRoom("horse", hallway);
//create door
Door * fence = addDoor("fence", frontyard, backyard, false, NULL);
Door * gate = addDoor("gate", frontyard, garage, false, NULL);
Door * gardenhousedoor = addDoor("garden house door", backyard, gardenhouse, false, NULL);
Door * verandadoor = addDoor("veranda door", backyard, veranda, false, NULL);
Door * kitchendoor = addDoor("kitchen door", veranda, kitchen, true, kitchenkey);
Door * mainentrance = addDoor("main entrance", frontyard, hallway, true, mainkey);
Door * garagedoor = addDoor("garage door", garage, hallway, true, garagekey);
Door * elevator = addDoor("elevator", hallway, landing, true, elevatorbutton);
Door * livingdoor = addDoor("living/hallway door", hallway, livingroom, false, NULL);
Door * kitchenlivingdoor = addDoor("living/kitchen door", livingroom, kitchen, false, NULL);
Door * storagedoor = addDoor("storage door", kitchen, storage, false, NULL);
Door * bathroomdoor = addDoor("bath room door", landing, bathroom, true, bathroomkey);
Door * bedroomdoor = addDoor("bedroom door", landing, bedroom, true, bedroomkey);
Door * guestroomdoor = addDoor("landing/guestroom door", landing, guestroom, false, NULL);
Door * balcony1 = addDoor("balcony/guestroom door", guestroom, balcony, false, NULL);
Door * balcony2 = addDoor("balcony/bedroom door", bedroom, balcony, false, NULL);
Door * hatch = addDoor("attic hatch", bedroom, frontattic, true, ladder);
Door * curtain = addDoor("curtain", frontattic, backattic, false, NULL);
Door * vaultdoor = addDoor("vault door", backattic, vault, true, drill);
// set player location
player->setCurrentRoom(frontyard);
// add something to inventory;
Item * chair = addItemToInventory("a plain chair");
}
Player * Playfield::getPlayer()
{
return player;
}
Room* Playfield::getRoom(string description)
{
vector<Room* >::iterator iter;
for (iter = rooms.begin(); iter!=rooms.end(); iter++)
{
if((*iter)->getDescription()==description)
{
return *iter;
}
}
return NULL;
}
Door* Playfield::getDoor(string description)
{
vector<Door* >::iterator iter;
for (iter = doors.begin(); iter!=doors.end(); iter++)
{
if((*iter)->getDescription()==description)
{
return *iter;
}
}
return NULL;
}
Item* Playfield::getItem(string description)
{
vector<Item* >::iterator iter;
for (iter = items.begin(); iter!=items.end(); iter++)
{
if((*iter)->getDescription()==description)
{
return *iter;
}
}
return NULL;
}
void Playfield::setPlayer(string name)
{
player = new Player();
player->setDescription("me");
player->setName(name);
}
Room * Playfield::addRoom(string description, string extendedDescription, string image)
{
Room * room = new Room();
room->setDescription(description);
room->setExtendedDescription(extendedDescription);
room->setImage(image);
rooms.push_back(room);
return room;
}
Door * Playfield::addDoor(string description, Room * roomOne, Room * roomTwo, bool locked, Item * key)
{
Door * door = new Door();
door->setDescription(description);
door->setRoomOne(roomOne);
roomOne->addDoor(door);
door->setRoomTwo(roomTwo);
roomTwo->addDoor(door);
if(locked)
{
door->lock(key);
}
doors.push_back(door);
return door;
}
Item* Playfield::addItemToRoom(string description, Room* room)
{
Item * item = new Item();
item->setDescription(description);
room->addItem(item);
items.push_back(item);
return item;
}
Item* Playfield::addItemToInventory(string description)
{
Item * item = new Item();
item->setDescription(description);
player->addItem(item);
items.push_back(item);
return item;
}