-
Notifications
You must be signed in to change notification settings - Fork 0
/
Screen.h
140 lines (121 loc) · 4.1 KB
/
Screen.h
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#ifndef SCREEN_H
#define SCREEN_H
#include ".\Board\Board.h"
#include ".\Board\Piece.h"
#include ".\Board\Color.h"
#include ".\Board\Position.h"
#include "Global.h"
#include ".\Checkers\CheckersMatch.h"
#include ".\Checkers\CheckersPosition.h"
#include ".\Checkers\Pieces\Checker.h"
#include <io.h>
#include <fcntl.h>
using namespace std;
class Screen{
public:
void static printMatch(CheckersMatch match)
{
printBoard(match.board);
cout <<"Turn: " << match.turn << endl;
}
void static printMatch(CheckersMatch match, vector<vector<bool>> possiblePositions)
{
printBoard(match.board, possiblePositions);
cout << "Turn: " << match.turn << endl;
}
void static printHeader()
{
cout << "*****************************" << endl;
cout << "****** CHECKERS GAME ******" << endl;
cout << "*****************************" << endl;
cout << "*** ***" << endl;
}
void static printBoard(Board board)
{
printHeader();
for(int i = 0; i<Dim; i++)
{
cout << (Dim -i) << " ";
for(int j = 0; j <Dim; j++)
{
SetConsole(board,Position(i,j));
//what is the problem?
Piece *p = board.piece(i, j);
cout << " " << *p << " ";
ResetConsole();
}
cout << endl;
}
cout << " a b c d e f g h"<< endl;
}
void static printBoard(Board board, vector<vector<bool>> possiblePositions)
{
printHeader();
for (int i = 0; i < Dim; i++)
{
cout << (Dim - i) << " ";
for (int j = 0; j < Dim; j++)
{
if(possiblePositions[i][j])
{
SetConsoleEspecial();
}
else SetConsole(board, Position(i, j));
// what is the problem?
Piece *p = board.piece(i, j);
cout << " " << *p << " ";
ResetConsole();
}
cout << endl;
}
cout << " a b c d e f g h"<< endl;
}
static CheckersPosition readCheckersPosition()
{
string s;
cin >> s;
char column = s[0];
int line = s[1]-'0';
if(s.size()==2){}
else if(s.size()>2)
throw runtime_error("Too much characters for a position!");
else
throw runtime_error("Too little characters for a position!");
if(column<'a' || column >'h' || line <1 || line >Dim)
throw runtime_error("Invalid entry!");
return CheckersPosition(column, line);
}
static void printWinner(Color winner)
{
if(winner == emptyColor) cout << endl << "WITHDRAW!!!" << endl;
else if(winner == black) cout << endl << "WINNER: Black" << endl;
else if (winner == white) cout << endl << "WINNER: White" << endl;
}
static void SetConsole(Board board, Position pos)
{
SetForeground(board, pos);
SetBackground(pos);
}
static void SetBackground(Position pos)
{
if((pos.line + pos.column)%2 == 0) cout << "\u001b[48;5;255m";
else cout << "\u001b[48;5;245m";
}
static void SetForeground(Board board, Position pos)
{
if(board.piece(pos)->getColor() == white)
cout << "\u001b[1m\u001b[38;5;160m";
else if(board.piece(pos)->getColor() == black)
cout << "\u001b[1m\u001b[38;5;0m";
}
static void SetConsoleEspecial()
{
//background configuration
cout << "\u001b[48;5;221m";
}
static void ResetConsole()
{
cout << "\u001b[0m";
}
};
#endif