-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathroom.cpp
More file actions
160 lines (139 loc) · 3.38 KB
/
room.cpp
File metadata and controls
160 lines (139 loc) · 3.38 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
#include <iostream>
#include <sstream>
#include "room.h"
#include "common.h"
#include "database.h"
using namespace std;
Room::Room(string t, string d){
title = t;
desc = d;
roomId = -1;
requirement == "No Req";
startingRoom = false;
}
Room::Room(string t, string d, string r){
title = t;
desc = d;
roomId = -1;
requirement = r;
}
void Room::save(){
string temp;
if(roomId == -1){
string north = getAdjacent("north")->getTitle();
string south = getAdjacent("south")->getTitle();
string east = getAdjacent("east")->getTitle();
string west = getAdjacent("west")->getTitle();
roomId = db->lastid;
stringstream converter;
bool b = isStartingRoom();
converter << boolalpha << b;
temp = "room \n title:"+getTitle()+"\n"+"desc:"+getDesc()+"\n"+converter.str()+"\n"+"north"+north+"\n"+"south"+south+"\n"+"east"+east+"\n"+"west"+west+"\n";
db->write(to_string(roomId),temp);
db->increment_lastid();
db->addRoom(this);
}
}
string Room::getRequirement() const {
return requirement;
}
string Room::getTitle() const {
return title;
}
string Room::getDesc() const {
return desc;
}
void Room::setAdjacent(string s, Room *r) {
exits[s] = r;
}
Room *Room::getAdjacent(string s) {
if(exits.find(s) != exits.end()) {
return exits[s];
} else {
return NULL;
}
}
map<string, Room*> Room::getExits() const {
return exits;
}
void Room::addItemToFloor(Item* item) {
floor.insert(item);
}
void Room::dropItemFromFloor(Item* item) {
floor.erase(item);
}
set<Item*> Room::getFloor() const {
return floor;
}
set<Item*> Room::getItems() const {
return floor;
}
Item* Room::findItemOnFloor(std::string name) const {
set<Item*>::const_iterator p;
for(p = floor.begin(); p != floor.end(); p++) {
if ((*p)->getName() == name) {
return *p;
}
}
cout << "ERROR: Item not found." << endl;
return NULL;
}
void Room::listItemsOnFloor() const {
set<Item*>::const_iterator p;
cout << "You scan the room and try to find anything useful." << endl;
/*
if (roomSet.size() == 0) {
cout << "There are no useful items in this room." << endl;
} else {
cout << "You can make out the faint out lines of the following items: " << endl;
for (p = floor.begin(); p != floor.end(); p++){
cout << (*p)->getName() << endl;
}
}
*/
}
void Room::setReq(string req)
{
string title = this->getTitle();
string description = this->getDesc();
Room(title, description, req);
}
void Room::setDesc(string description)
{
string req = this->getRequirement();
string title = this->getTitle();
if(roomhaveReq())
{
Room(title, description, req);
}
else
{
Room(title, description);
}
}
void Room::setreqMove(string oldroom, string req, string newroom)
{
if(this->roomhaveReq())
{
}
}
void Room::setChance(string oldRoom, double chance, string newroom)
{
}
bool Room::roomhaveReq()
{
if(this->getRequirement() == "No Req")
{
return false;
}
else
{
return true;
}
}
void Room::setStartingRoom(bool b) {
startingRoom = b;
}
bool Room::isStartingRoom() const {
return startingRoom;
}