-
Notifications
You must be signed in to change notification settings - Fork 0
/
textdisplay.cc
52 lines (47 loc) · 1.26 KB
/
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
45
46
47
48
49
50
51
52
#include "textdisplay.h"
#include <iostream>
#include <string>
using namespace std;
// constructor
TextDisplay::TextDisplay() {
for (int i = 0; i < boardSize; i++) {
vector<char> row;
for (int j = 0; j < boardSize; j++) {
row.emplace_back('_');
}
td.emplace_back(row);
}
}
// destructor
TextDisplay::~TextDisplay() {}
// updates the text display of the chess board
void TextDisplay::tdNotify(char colour, char pieceLetter, int row, int col) {
if (colour == 'w') {
td[row][col] = pieceLetter - 32;
}
else if (colour == 'b') {
td[row][col] = pieceLetter;
}
else { // if empty
td[row][col] = '_';
}
}
// displays the chess board
ostream &operator<<(std::ostream &out, const TextDisplay &td) {
int rownum = 8;
for (int row = 0; row < td.boardSize; row++) {
cout << rownum << " "; // prints the row number
rownum--;
for (int col = 0; col < td.boardSize; col++) {
if (col == td.boardSize - 1) {
out << td.td[row][col] << endl;
}
else {
out << td.td[row][col];
}
}
}
cout << endl;
cout << " abcdefgh" << endl; // prints the column letters
return out;
}