-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScreen.cs
145 lines (133 loc) · 4.93 KB
/
Screen.cs
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
141
142
143
144
145
using Board;
using Chess;
namespace ChessInConsole
{
class Screen
{
public static void PrintChessMatch(ChessMatch chessMatch)
{
BoardView(chessMatch.Board);
Console.WriteLine();
PrintCapturedPieces(chessMatch);
if (!chessMatch.EndMatch)
{
Console.WriteLine($"\nTurno: {chessMatch.Turn}\n" +
$"Waiting move from: {chessMatch.PlayerColor}");
if (chessMatch.Check) Console.WriteLine("\nCheck!");
}
else
{
Console.WriteLine("\nCheckmate!\n" +
$"Winner: {chessMatch.PlayerColor}");
}
}
private static void PrintCapturedPieces(ChessMatch chessMatch)
{
Console.WriteLine($"Captured Pieces:");
ConsoleColor consoleColor = Console.ForegroundColor;
Console.ForegroundColor = ConsoleColor.White;
Console.Write($"White: [");
List<Piece> pieces = chessMatch.ColorCapturedPieces(Color.White).ToList();
for (int i = 0; i < pieces.Count; i++)
{
if (i != pieces.Count - 1) Console.Write($"{pieces[i]} ");
else Console.Write(pieces[i]);
}
Console.WriteLine("]");
Console.ForegroundColor = ConsoleColor.Yellow;
Console.Write("Black: [");
pieces = chessMatch.ColorCapturedPieces(Color.Black).ToList();
for (int i = 0; i < pieces.Count; i++)
{
if (i != pieces.Count - 1) Console.Write($"{pieces[i]} ");
else Console.Write(pieces[i]);
}
Console.WriteLine("]");
Console.ForegroundColor = consoleColor;
}
public static void BoardView(ChessBoard board)
{
for (int i = 0; i < board.Lines; i++)
{
Console.Write($"{8 - i} ");
for (int j = 0; j < board.Columns; j++)
{
if (j != board.Columns - 1)
{
PiecePrint(board.PiecePosition(i, j));
Console.Write(" ");
}
else
{
PiecePrint(board.PiecePosition(i, j));
Console.WriteLine();
}
}
}
Console.Write(" ");
for (int i = 0; i < board.Columns; i++)
{
if (i != board.Columns - 1) Console.Write($"{(char)('a' + i)} ");
else Console.WriteLine($"{(char)('a' + i)}");
}
}
public static void BoardView(ChessBoard board, bool[,] possibleMovements)
{
ConsoleColor originalBackground = Console.BackgroundColor;
for (int i = 0; i < board.Lines; i++)
{
Console.Write($"{8 - i} ");
for (int j = 0; j < board.Columns; j++)
{
if (possibleMovements[i, j]) Console.BackgroundColor = ConsoleColor.DarkGray;
if (j != board.Columns - 1)
{
PiecePrint(board.PiecePosition(i, j));
Console.BackgroundColor = originalBackground;
Console.Write(" ");
}
else
{
PiecePrint(board.PiecePosition(i, j));
Console.BackgroundColor = originalBackground;
Console.WriteLine();
}
}
}
Console.Write(" ");
for (int i = 0; i < board.Columns; i++)
{
if (i != board.Columns - 1) Console.Write($"{(char)('a' + i)} ");
else Console.WriteLine($"{(char)('a' + i)}");
}
}
public static ChessCoordinate ReadPosition()
{
string imput = Console.ReadLine();
char line = imput[0];
int column = int.Parse(imput[1] + "");
return new ChessCoordinate(line, column);
}
public static void PiecePrint(Piece piece)
{
if (piece == null)
{
Console.Write("-");
}
else if (piece.Color == Color.White)
{
ConsoleColor consoleColor = Console.ForegroundColor;
Console.ForegroundColor = ConsoleColor.White;
Console.Write(piece);
Console.ForegroundColor = consoleColor;
}
else
{
ConsoleColor consoleColor = Console.ForegroundColor;
Console.ForegroundColor = ConsoleColor.Yellow;
Console.Write(piece);
Console.ForegroundColor = consoleColor;
}
}
}
}