-
Notifications
You must be signed in to change notification settings - Fork 1
/
Board.cc
195 lines (171 loc) · 4.57 KB
/
Board.cc
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#include "Board.h"
#include "commandInput.h"
// map that stores the information of all Academic buildings
std::map <int, std::string> academic = {
{1, "AL "},
{3, "ML "},
{6, "ECH "},
{8, "PAS "},
{9, "HH "},
{11, "RCH "},
{13, "DWE "},
{14, "CPH "},
{16, "LHI "},
{18, "BMH "},
{19, "OPT "},
{21, "EV1 "},
{23, "EV2 "},
{24, "EV3 "},
{26, "PHYS "},
{27, "B1 "},
{29, "B2 "},
{31, "EIT "},
{32, "ESC "},
{34, "C2 "},
{37, "MC "},
{39, "DC "}
};
// map that stores the information of all longname buildings
std::map <int, std::vector<std::string>> longName = {
{0, {"COLLECT", "OSAP "}},
{7, {"NEEDLES", "HALL "}},
{10, {"DC Tims", "Line "}},
{20, {"Goose ", "Nesting"}},
{0, {"COLLECT", "OSAP "}},
{22, {"NEEDLES", "HALL "}},
{30, {"GO TO ", "TIMS "}},
{36, {"NEEDLES", "HALL "}},
{38, {"COOP ", "FEE "}}
};
// map that stores the information of all other buildings
std::map <int, std::string> other = {
{2, "SLC "},
{4, "TUITION"},
{5, "MKV "},
{12, "PAC "},
{15, "UWP "},
{17, "SLC "},
{25, "V1 "},
{28, "CIF "},
{33, "SLC "},
{35, "REV "}
};
void Board::setCommand(CommandInput * c) {
command = c;
}
Board::Board() {
// initializes the command to null pointer
command = nullptr;
// sets the length of vector for easier storage
std::vector<std::string> piece(7, "");
board = std::vector<std::vector<std::string>>(40, piece);
// constructs the initial board template
for (int i = 0; i < 40; i++) {
if (academic.count(i) == 1) {
board[i][0] = " ------- ";
board[i][1] = "| |";
board[i][2] = "|-------|";
board[i][3] = "|" + academic[i] + "|";
board[i][4] = "| |";
board[i][5] = "| |";
board[i][6] = " ------- ";
} else if (longName.count(i) == 1) {
board[i][0] = " ------- ";
board[i][1] = "|" + longName[i][0] + "|";
board[i][2] = "|" + longName[i][1] + "|";
board[i][3] = "| |";
board[i][4] = "| |";
board[i][5] = "| |";
board[i][6] = " ------- ";
} else {
board[i][0] = " ------- ";
board[i][1] = "|" + other[i] + "|";
board[i][2] = "| |";
board[i][3] = "| |";
board[i][4] = "| |";
board[i][5] = "| |";
board[i][6] = " ------- ";
}
}
}
CommandInput * Board::getCommand() {
return command;
}
void Board::updateImprovement(std::shared_ptr<Academic> academic) {
// gets the current improvement number
int improvementNumber = academic->getImprovement();
// gets the position of the building
int position = academic->getPosition();
// sets the old string to empty
std::string temp = "| |";
for (int i = 0; i < improvementNumber; i++) {
temp[i + 1] = 'I';
}
board[position][1] = temp;
}
void Board::updatePlayer(int oldPosition, int newPosition, std::string playerName) {
char symbol = playerName[0];
// for initial representation of players' position
if (!((oldPosition == 0) && (newPosition == 0))) {
for (int i = 1; i < 9; i += 2) {
if (board[oldPosition][4][i] == symbol) {
board[oldPosition][4][i] = ' ';
}
}
for (int i = 1; i < 9; i += 2) {
if (board[oldPosition][5][i] == symbol) {
board[oldPosition][5][i] = ' ';
}
}
}
for (int i = 1; i < 9; i += 2) {
if (board[newPosition][4][i] == ' ') {
board[newPosition][4][i] = symbol;
return;
}
}
for (int i = 1; i < 9; i += 2) {
if (board[newPosition][5][i] == ' ') {
board[newPosition][5][i] = symbol;
return;
}
}
}
void Board::removePlayer(int position, std::string playerName) {
char symbol = playerName[0];
for (int i = 1; i < 9; i += 2) {
if (board[position][4][i] == symbol) {
board[position][4][i] = ' ';
}
}
for (int i = 1; i < 9; i += 2) {
if (board[position][5][i] == symbol) {
board[position][5][i] = ' ';
}
}
}
void Board::printMessage(std::string message, std::ostream & out) {
out << message << std::endl;
}
void Board::drawBoard(std::ostream & out) {
for (int h = 0; h < 7; h++) {
for (int w = 20; w <= 30; w++) {
out << board[w][h];
}
out << "\n";
}
for (int i = 19; i > 10; i--) {
for (int h = 0; h < 7; h++) {
out << board[i][h];
out << std::setw(90);
out << board[40 - i + 10][h];
out << "\n";
}
}
for (int h = 0; h < 7; h++) {
for (int w = 10; w >= 0; w--) {
out << board[w][h];
}
out << "\n";
}
}