-
Notifications
You must be signed in to change notification settings - Fork 0
/
textdisplay.cc
44 lines (31 loc) · 877 Bytes
/
textdisplay.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
#include "textdisplay.h"
using namespace std;
TextDisplay::TextDisplay(int n)
: theDisplay{vector<vector<char>>{}}, gridSize{n * n} {
theDisplay.assign(n, vector<char>{});
for (auto &row : theDisplay) {
row.assign(n, '-');
}
}
void TextDisplay::notify(Subject<Info, State> &whoNotified) {
State senderSignal = whoNotified.getState();
Info senderInfo = whoNotified.getInfo();
if (senderSignal.type == StateType::Relay)
return;
if (senderInfo.colour == Colour::Black) {
theDisplay[senderInfo.row][senderInfo.col] = 'B';
} else if (senderInfo.colour == Colour::White) {
theDisplay[senderInfo.row][senderInfo.col] = 'W';
} else {
return;
}
}
ostream &operator<<(ostream &out, const TextDisplay &td) {
for (auto row : td.theDisplay) {
for (auto chr : row) {
out << chr;
}
out << endl;
}
return out;
}