-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRoom.cpp
More file actions
84 lines (71 loc) · 2.04 KB
/
Room.cpp
File metadata and controls
84 lines (71 loc) · 2.04 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
//
// Created by CalPC on 11/27/2018.
//
#include "Room.h"
#include <vector>
using namespace std;
Room::Room(string roomDescription) {
this->roomDescription = roomDescription;
names = BASIC_NAMES;
}
Room::Room(vector<string> names, string roomDescription) {
this->roomDescription = roomDescription;
this->names = names;
for (unsigned int i = 0; i < names.size(); i++) {
this->names.push_back("the " + names.at(i));
}
for (unsigned int i = 0; i < BASIC_NAMES.size(); i++) {
this->names.push_back(BASIC_NAMES.at(i));
}
}
string Room::getRoomDescription() {
return roomDescription;
}
void Room::addItem(Item* newItem) {
roomItems.push_back(newItem);
}
void Room::removeItem(string itemName) {
for(unsigned int i = 0; i < roomItems.size(); i++) {
if (roomItems.at(i)->hasName(itemName)) {
roomItems.erase(roomItems.begin() + i);
i = roomItems.size();
}
}
}
bool Room::hasItem(string itemName) {
for(unsigned int i = 0; i < roomItems.size(); i++) {
if (roomItems.at(i)->hasName(itemName)) return true;
}
return false;
}
Item* Room::getItem(string itemName) { // this is a memory leak waiting to happen...
for(unsigned int i = 0; i < roomItems.size(); i++) {
if (roomItems.at(i)->hasName(itemName)) {
return roomItems.at(i);
}
}
return new Item({"nada"},"","",{});
}
vector<Item*> Room::getRoomItems() {
return roomItems;
}
void Room::addExit(vector<string> direction, int room) {
for (unsigned int i = 0; i < direction.size(); i ++) {
exits.emplace(direction.at(i), room);
}
}
int Room::exit(string direction) {
if (exits.count(direction) == 0) return -1;
return exits.at(direction);
}
bool Room::hasName(string name) {
for (unsigned int i = 0; i < names.size(); i++) {
if (names.at(i) == name) return true;
}
return false;
}
void Room::deleteItems() {
for (unsigned int i = 0; i < roomItems.size(); i++) {
delete roomItems.at(i);
}
}