Skip to content

Commit 9db6838

Browse files
committed
Little improvement in board printing
1 parent 3d983c8 commit 9db6838

File tree

3 files changed

+52
-17
lines changed

3 files changed

+52
-17
lines changed
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
eclipse.preferences.version=1
22
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3-
org.eclipse.jdt.core.compiler.codegen.targetPlatform=12
3+
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
4+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
45
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5-
org.eclipse.jdt.core.compiler.compliance=12
6+
org.eclipse.jdt.core.compiler.compliance=1.8
67
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
78
org.eclipse.jdt.core.compiler.debug.localVariable=generate
89
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
910
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
1011
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
1112
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
1213
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
13-
org.eclipse.jdt.core.compiler.release=enabled
14-
org.eclipse.jdt.core.compiler.source=12
14+
org.eclipse.jdt.core.compiler.release=disabled
15+
org.eclipse.jdt.core.compiler.source=1.8

src/application/UI.java

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,52 @@
11
package application;
22

33
import chess.ChessPiece;
4+
import chess.Color;
45

56
public class UI {
6-
7+
public static final String ANSI_RESET = "\u001B[0m";
8+
public static final String ANSI_BLACK = "\u001B[30m";
9+
public static final String ANSI_RED = "\u001B[31m";
10+
public static final String ANSI_GREEN = "\u001B[32m";
11+
public static final String ANSI_YELLOW = "\u001B[33m";
12+
public static final String ANSI_BLUE = "\u001B[34m";
13+
public static final String ANSI_PURPLE = "\u001B[35m";
14+
public static final String ANSI_CYAN = "\u001B[36m";
15+
public static final String ANSI_WHITE = "\u001B[37m";
16+
17+
public static final String ANSI_BLACK_BACKGROUND = "\u001B[40m";
18+
public static final String ANSI_RED_BACKGROUND = "\u001B[41m";
19+
public static final String ANSI_GREEN_BACKGROUND = "\u001B[42m";
20+
public static final String ANSI_YELLOW_BACKGROUND = "\u001B[43m";
21+
public static final String ANSI_BLUE_BACKGROUND = "\u001B[44m";
22+
public static final String ANSI_PURPLE_BACKGROUND = "\u001B[45m";
23+
public static final String ANSI_CYAN_BACKGROUND = "\u001B[46m";
24+
public static final String ANSI_WHITE_BACKGROUND = "\u001B[47m";
25+
726
public static void printBoard(ChessPiece[][] pieces) {
8-
for(int i=0; i<pieces.length; i++) {
27+
for (int i = 0; i < pieces.length; i++) {
928
System.out.print((8 - i) + " ");
10-
for(int j=0; j<pieces.length; j++) {
29+
for (int j = 0; j < pieces.length; j++) {
1130
printPiece(pieces[i][j]);
1231
}
1332
System.out.println();
1433
}
1534
System.out.println(" A B C D E F G H");
1635
}
17-
18-
private static void printPiece(ChessPiece piece) {
19-
if(piece == null) {
36+
37+
private static void printPiece(ChessPiece piece) {
38+
if (piece == null) {
2039
System.out.print("-");
2140
}
22-
else {
23-
System.out.print(piece);
24-
}
25-
System.out.print(" ");
41+
else {
42+
if (piece.getColor() == Color.WHITE) {
43+
System.out.print(ANSI_WHITE + piece + ANSI_RESET);
44+
}
45+
else {
46+
System.out.print(ANSI_YELLOW + piece + ANSI_RESET);
47+
}
48+
}
49+
System.out.print(" ");
2650
}
2751

2852
}

src/chess/ChessMatch.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,18 @@ private void placeNewPiece(char column, int row, ChessPiece piece) {
2727
}
2828

2929
private void initialSetup() {
30-
placeNewPiece('b', 6, new Rook(board, Color.WHITE));
31-
placeNewPiece('e', 8, new King(board, Color.BLACK));
32-
placeNewPiece('e', 1, new King(board, Color.WHITE));
30+
placeNewPiece('c', 1, new Rook(board, Color.WHITE));
31+
placeNewPiece('c', 2, new Rook(board, Color.WHITE));
32+
placeNewPiece('d', 2, new Rook(board, Color.WHITE));
33+
placeNewPiece('e', 2, new Rook(board, Color.WHITE));
34+
placeNewPiece('e', 1, new Rook(board, Color.WHITE));
35+
placeNewPiece('d', 1, new King(board, Color.WHITE));
36+
37+
placeNewPiece('c', 7, new Rook(board, Color.BLACK));
38+
placeNewPiece('c', 8, new Rook(board, Color.BLACK));
39+
placeNewPiece('d', 7, new Rook(board, Color.BLACK));
40+
placeNewPiece('e', 7, new Rook(board, Color.BLACK));
41+
placeNewPiece('e', 8, new Rook(board, Color.BLACK));
42+
placeNewPiece('d', 8, new King(board, Color.BLACK));
3343
}
3444
}

0 commit comments

Comments
 (0)