-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfloor.cpp
More file actions
158 lines (141 loc) · 3.64 KB
/
Copy pathfloor.cpp
File metadata and controls
158 lines (141 loc) · 3.64 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
#include "floor.h"
int Floor::floorNum = 0;
Floor::Floor(Character& character, Inventory& inv) : character(character), i(inv), dimension(10), floor(dimension, std::vector<Event*>(dimension)) {
floorNum++;
int randNum;
int merchX, merchY;
//Set Ladder
do {
ladderX = getRand();
ladderY = getRand();
} while (ladderX == 0 && ladderY == 4); //don't spawn ladder right where character lands
floor[ladderX][ladderY] = new Ladder(character, i);
do {
merchX = getRand();
merchY = getRand();
} while ((merchX == 0 && merchY == 4) || (merchX == ladderX && merchY == ladderY)); //don't spawn merchant right where character lands
floor[merchX][merchY] = new Merchant(character, i);
//Generate # between 0 - 50;
//0 - 5 : monster, 6 - 7 = chest, else = no event
for (int r = 0; r < dimension; r++) {
for (int c = 0; c < dimension; c++) {
if (floor[r][c] == 0) { //uninitialized coordinate
randNum = rand() % 51;
if (randNum >= 0 && randNum <= 5) {
floor[r][c] = new Battle(character, i, floorNum);
}
else if (randNum >= 6 && randNum <= 7) {
floor[r][c] = new Chest(character, i);
}
else {
floor[r][c] = new NoEvent(character, i);
}
}
}
}
for (int r = 0; r < dimension; r++) {
for (int c = 0; c < dimension; c++) {
if (floor[r][c] == 0) { //uninitialized coordinate
randNum = rand() % 51;
if (randNum >= 0 && randNum <= 5) {
floor[r][c] = new Battle(character, i, floorNum);
}
else if (randNum >= 6 && randNum <= 7) {
floor[r][c] = new Chest(character, i);
}
else {
floor[r][c] = new NoEvent(character, i);
}
}
}
}
//0,4 is spawn point, so make it a revealed NoEvent Tile
delete floor[0][4];
floor[0][4] = new NoEvent(character, i);
floor[0][4]->visit(); //reveal
}
bool Floor::moveCharacter(char direction) {
int x = character.getX(), y = character.getY();
bool moved;
switch (direction) {
case 'w': //Up
if (y - 1 < 0) {
moved = false;
}
else {
character.setCoor(x, y - 1);
moved = true;
}
break;
case 'd': //Right
if (x + 1 >= dimension) {
moved = false;
}
else {
character.setCoor(x + 1, y);
moved = true;
}
break;
case 's': //Down
if (y + 1 >= dimension) {
moved = false;
}
else {
character.setCoor(x, y + 1);
moved = true;
}
break;
case 'a': //Left
if (x - 1 < 0) {
moved = false;
}
else {
character.setCoor(x - 1, y);
moved = true;
}
break;
default:
return false; //Int on range [0,4] not entered
}
floor[character.getY()][character.getX()]->performEvent();
return moved;
}
std::ostream& operator<<(std::ostream& out, const Floor& f) {
out << std::left;
int charX = f.character.getX(), charY = f.character.getY();
out << "Currently on " << f.character.getCurrentFloor() + 1 << "F" << std::endl;
for (int r = 0; r < f.dimension; r++) {
for (int c = 0; c < f.dimension; c++) {
out << std::setw(4);
if (r == charY && c == charX)
out << "YOU";
else
out << f.floor[r][c]->getSymbol();
out << " ";
}
out << std::endl << std::endl;
}
out << f.character << std::endl;
return out;
}
void Floor::revealAll() {
for (int r = 0; r < dimension; r++) {
for (int c = 0; c < dimension; c++) {
floor[r][c]->visit();
}
}
}
void Floor::hideAll() {
for (int r = 0; r < dimension; r++) {
for (int c = 0; c < dimension; c++) {
floor[r][c]->unVisit();
}
}
}
bool Floor::revealLadder() {
if (!floor[ladderX][ladderY]->getIsVisited()) {
floor[ladderX][ladderY]->visit();
return true;
}
return false;
}