-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMap.cpp
81 lines (76 loc) · 1.71 KB
/
Map.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
#include "Map.h"
#include "ObjectTracker.h"
#include <random>
Map::Map(int _id, std::string _name)
{
id = _id;
name = _name;
}
void Map::fillRooms(ObjectTracker* _o)
{
if (validEnemies.size() == 0 || validLoot.size() == 0) {
std::cout << "Need to add enemies or loot to the map to load!";
return;
}
for (int x = 0; x < 4; x++) {
for (int y = 0; y < 4; y++) {
int type = rand() % 12;
Room r;
if (type >= 0 && type <= 3) {
r = Room();
}
else if (type >= 4 && type <= 6) {
Container* _loot = _o->getContainer(validLoot.at(rand() % validLoot.size()));
r = Room(_loot);
}
else if (type >= 7 && type <= 11) {
Character* _enemy = _o->getCharacter(validEnemies.at(rand() % validEnemies.size()));
r = Room(_enemy);
}
rooms[x][y] = r;
}
}
}
int Map::roomsCleared_()
{
int numRooms = 0;
for (int x = 0; x < 4; x++) {
for (int y = 0; y < 4; y++) {
if (rooms[x][y].clear_()) {
numRooms++;
}
}
}
return numRooms;
}
void Map::printMap(int p_x, int p_y)
{
char rep;
for (int y = 0; y < 4; y++) {
std::cout << "+---+---+---+---+" << std::endl;
std::cout << "| | | | |" << std::endl;
for (int x = 0; x < 4; x++) {\
if (x == p_x && y == p_y) {
rep = 'P';
}
else if (rooms[x][y].clear_()) {
rep = 'C';
}
else {
rep = '?';
}
std::cout << "| " << rep << " ";
}
std::cout << "|" << std::endl;
std::cout << "| | | | |" << std::endl;
}
std::cout << "+---+---+---+---+" << std::endl;
}
int* Map::printMoveMenu(int p_x, int p_y)
{
std::cout << "[1]Move North" << std::endl;
std::cout << "[2]Move East" << std::endl;
std::cout << "[3]Move South" << std::endl;
std::cout << "[4]Move West" << std::endl;
return new int[2]{ 1,4 };
}