-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroom.cpp
More file actions
112 lines (89 loc) · 1.72 KB
/
Copy pathroom.cpp
File metadata and controls
112 lines (89 loc) · 1.72 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
#include "room.h"
#include "item.h"
#include <time.h>
#include <set>
#include <stdexcept>
using namespace WoS;
using namespace std;
Room::Room(const int ID, const string name, const string description)
{
rID = ID;
rName = name;
rDescription = description;
needsKey = false;
}
Room::~Room()
{
}
void Room::addNeighbour(string str, Room* room)
{
neighbours.insert(pair<string,Room*>(str,room));
}
Room* Room::getNeighbour(string direction) const
{
try{
return neighbours.at(direction);
}
catch(...)
{
return NULL;
}
}
const int Room::ID() const
{
return rID;
}
const string Room::getName() const
{
return rName;
}
Item* Room::removeItem(string item)
{
try{
Item* tmp = items.at(item);
items.erase(item);
return tmp;
}
catch(...)
{
return NULL;
}
}
bool Room::addItem(Item* item)
{
try{
items.insert(pair<string,Item*>(item->getName(),item));
return true;
}
catch(...)
{
return false;
}
}
void Room::print(bool eItems) const
{
cout << rDescription << endl;
if(eItems && items.size()>0)
{
cout << "in the room you can find: " << endl;
for(map<string, Item*>::const_iterator it = items.begin(); it != items.end(); ++it)
{
cout << it->first << endl;
}
}
}
void Room::printDirections() const
{
for(map<string, Room*>::const_iterator it = neighbours.begin(); it != neighbours.end(); ++it)
{
cout << it->first << " -> " << it->second->getName() << endl;
}
}
string Room::getRandomDirection() const
{
srand ( time(NULL) );
map<string,Room*>::const_iterator it = neighbours.begin();
int random = rand() % neighbours.size();
advance( it, random);
return it->first;
}