-
Notifications
You must be signed in to change notification settings - Fork 0
/
Render.cc
68 lines (59 loc) · 1.93 KB
/
Render.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
#include "Render.h"
// printTextBoard(b) displays the Board in text
void Render::printTextBoard(Board &b)
{
cout << endl
<< "Current board is:" << endl;
for (int row = 8; row >= 1; --row)
{
cout << row << " ";
for (int col = 1; col <= 8; ++col)
{
char pc = b.piece(row, col);
char BnW = (row + col) % 2 ? ' ' : '_';
cout << (pc ? pc : BnW);
}
cout << endl;
}
cout << endl
<< " abcdefgh" << endl;
}
// printGraphicBoard(b) displays the Board in graphics
void Render::printGraphicBoard(Board &b)
{
wd = make_unique<Xwindow>();
Xwindow &w = *wd;
w.fillRectangle(0, 0, 510, 510, Xwindow::White);
w.drawString(10, 10, "Current board is:", Xwindow::Black);
const int STRING_SIZE{35};
const int CELL_SIZE{50};
int x{STRING_SIZE};
for (int row{8}; row >= 1; --row)
{
// drawing the initial vertical numbered coordinates
w.drawBigString(5, x + STRING_SIZE + 5, to_string(row) + " ", Xwindow::Black);
int y{5 + STRING_SIZE};
for (int col = 1; col <= 8; ++col)
{
char pc = b.piece(row, col);
bool isCellWhite{(row + col) % 2 ? true : false};
w.fillRectangle(y, x, CELL_SIZE, CELL_SIZE, isCellWhite ? Xwindow::White : Xwindow::Black);
if (pc)
{
string s(1, pc);
w.drawBigString(y + 15, x + STRING_SIZE, s, Xwindow::Yellow);
}
y += CELL_SIZE + 1;
}
x += CELL_SIZE + 1;
w.drawBigString(STRING_SIZE, y + STRING_SIZE,
" a b c d e f g h", Xwindow::Black);
}
}
// printBoard(b) displays the Board in graphic
void Render::printBoard(Board &b)
{
isGraphic ? printGraphicBoard(b) : printTextBoard(b);
}
// Render(isGraphic) constructs a Render object
Render::Render(bool isGraphic) : isGraphic{isGraphic} {}