-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGraphicsObserver.cc
More file actions
67 lines (51 loc) · 1.64 KB
/
GraphicsObserver.cc
File metadata and controls
67 lines (51 loc) · 1.64 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
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
#ifndef VIEW
#define VIEW 0
#endif
#include <iostream>
#include "GraphicsObserver.h"
#include "Window.h"
using namespace std;
GraphicsObserver::GraphicsObserver(ChessBoard *board): board{board} {
board->attach(this);
#if VIEW >= 1
window = new Xwindow(900,900);
#endif
}
GraphicsObserver::~GraphicsObserver() {
board->detach(this);
#if VIEW >= 1
delete window;
#endif
}
void GraphicsObserver::notify() {
#if VIEW >= 1
/*
for(int i = 7; i >= 0; --i){ //starts from a8 (0,0)
for(int j = 0; j < 8; j++){
int xCor = 100*j;
int yCor = 100*(7-i);
bool isWhiteSquare = ((i+j)%2 == 0);
if (isWhiteSquare) window->fillRectangle(xCor,yCor,100,100,window->White);
else window->fillRectangle(xCor,yCor,100,100,window->Black);
}
}
*/
//window->f();
for(int j = 0; j < 8; j++){
for(int i = 7; i >= 0; --i){ //starts from a8 (0,0)
int xCor = 50+100*(j);
int yCor = 50+100*(7-i);
bool isWhiteSquare = ((i+j)%2 == 1);
if(board->isOccupied(make_pair(i, j))) {
Piece* piece = board->getPiece(make_pair(i, j));
bool isWhitePiece = piece->isWhite();
char p = piece->getPieceSymbol();
window->drawPiece(p, isWhitePiece, isWhiteSquare, xCor, yCor);
} else {
if (isWhiteSquare) window->fillRectangleCustom(xCor,yCor,100,100,3);
else window->fillRectangleCustom(xCor,yCor,100,100,2);
}
}
}
#endif
}