-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTextObserver.cc
More file actions
40 lines (34 loc) · 1.02 KB
/
TextObserver.cc
File metadata and controls
40 lines (34 loc) · 1.02 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
#include <iostream>
#include "TextObserver.h"
using namespace std;
TextObserver::TextObserver(ChessBoard *board): board{board} {
board->attach(this);
}
TextObserver::~TextObserver() {
board->detach(this);
}
void TextObserver::notify() {
for(int i = 7; i >= 0; --i){ //starts from a8 (0,0)
cout << i + 1 << " ";
for(int j = 0; j < 8; j++){
if(board->isOccupied(make_pair(i, j))){
Piece* piece = board->getPiece(make_pair(i, j));
if(piece->isWhite()){
cout << piece->getPieceSymbol();
} else {
char lower = tolower(piece->getPieceSymbol());
cout << lower;
}
} else {
//check for white or black square
if((i+j)%2 == 0){
cout << ' ';
} else{
cout << '_';
}
}
}
cout << endl;
}
cout << endl << " ABCDEFGH" << endl;
}