-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroom.cpp
141 lines (118 loc) · 2.69 KB
/
room.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
#include "h_files/room.h"
#include "h_files/player.h"
#include "h_files/items.h"
#include <iostream>
using namespace std;
void room::init(int rid, bool lock, int req, string failed, int post[2], vector<entity> entities_list, bool connections[4], bool is_placeholder, bool is_active){
id = rid;
locked = lock;
requirement = req;
failed_requirement = failed;
for (int i = 0; i < 4;i++){
connects[i] = connections[i];
}
pos[0] = post[0];
pos[1] = post[1];
entities = entities_list;
placeholder = is_placeholder;
active = is_active;
build_room();
}
bool is_exit(){
return exit;
}
void room::make_exit(){
exit = true;
}
int room::get_id(){
return id;
}
bool room::is_locked(){
return locked;
}
int room::get_requirement(){
return requirement;
}
string room::get_failed_requirement(){
return failed_requirement;
}
int* room::get_pos(){
return pos;
}
bool room::is_placeholder(){
return placeholder;
}
void room::unlock(player &play){
//check if player has the requirement and unlock if they have it.
item req;
if(play.has_item(requirement)){
play.use_item(requirement);
}
}
void room::remove_placeholder(){
placeholder = false;
}
void room::change_connection(int direction){
if(connects[direction] == true){
connects[direction] = false;
}else{
connects[direction] = true;
}
}
void room::build_room(){
room_structure.clear();
if(is_placeholder() == true){
for (int i = 0; i < 7;i++){
room_structure.push_back(" ");
}
return;
}
string space=" ";
// one mid has a length of 9
string mid = "#" + space + "#";
// mid now has 54 size exits will be on at the start and end - 1 of row indices 2 and 3.
if (connects[0]){
room_structure.push_back("### ###");
}else{
room_structure.push_back("#########");
}
for (int i = 0; i < 5;i++){
room_structure.push_back(mid);
}
if (connects[3]){
room_structure[2][0] = ' ';
room_structure[3][0] = ' ';
room_structure[4][0] = ' ';
}
if(connects[1]){
room_structure[2][room_structure[2].size() - 1] = ' ';
room_structure[3][room_structure[3].size() - 1] = ' ';
room_structure[4][room_structure[4].size() - 1] = ' ';
}
if (connects[2]){
room_structure.push_back("### ###");
}else{
room_structure.push_back("#########");
}
if(active == true){
string &part = room_structure[room_structure.size() / 2];
part[part.size() / 2] = 'p';
}
return;
}
bool* room::get_connections(){
return connects;
}
vector<string> room::get_structure(){
return room_structure;
}
void room::change_active(){
if(active == true){
active = false;
}else{
active = true;
}
}
bool room::is_active(){
return active;
}