color changes in console + promotion
This commit is contained in:
@@ -38,4 +38,8 @@ public class Coordinate {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "(" + this.x + ", " + this.y + ")";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,15 +7,17 @@ public class Colors {
|
||||
// Regular Colors
|
||||
public static final String BLACK = "\033[38;2;0;0;0m";
|
||||
public static final String WHITE = "\033[38;2;255;255;255m";
|
||||
public static final String RED = "\u001B[31m";
|
||||
public static final String GREEN = "\u001B[32m";
|
||||
public static final String YELLOW = "\u001B[33m";
|
||||
public static final String BLUE = "\u001B[34m";
|
||||
public static final String PURPLE = "\u001B[35m";
|
||||
public static final String CYAN = "\u001B[36m";
|
||||
public static final String RED = "\033[38;2;255;0;0m";
|
||||
public static final String GREEN = "\033[38;2;0;255;0m";
|
||||
public static final String YELLOW = "\033[38;2;255;255;0m";
|
||||
public static final String BLUE = "\033[38;2;0;0;255m";
|
||||
public static final String PURPLE = "\033[38;2;255;0;255m";
|
||||
public static final String CYAN = "\033[38;2;0;255;255m";
|
||||
|
||||
// Background
|
||||
public static final String BLACK_BACKGROUND = "\033[40m"; // BLACK
|
||||
public static final String LIGHT_GRAY_BACKGROUND = "\033[48;2;180;180;180m";
|
||||
public static final String DARK_GRAY_BACKGROUND = "\033[48;2;120;120;120m";
|
||||
public static final String RED_BACKGROUND = "\033[41m"; // RED
|
||||
public static final String GREEN_BACKGROUND = "\033[42m"; // GREEN
|
||||
public static final String YELLOW_BACKGROUND = "\033[43m"; // YELLOW
|
||||
|
||||
@@ -56,7 +56,6 @@ public class Console implements GameListener {
|
||||
|
||||
@Override
|
||||
public void playerTurn(Color color) {
|
||||
updateDisplay();
|
||||
System.out.println(Colors.RED + "Player turn: " + color + Colors.RESET);
|
||||
boolean endTurn;
|
||||
do {
|
||||
@@ -74,6 +73,7 @@ public class Console implements GameListener {
|
||||
};
|
||||
} while (!endTurn);
|
||||
System.out.println(Colors.RED + "Turn ended." + Colors.RESET);
|
||||
updateDisplay();
|
||||
}
|
||||
|
||||
private boolean playerPickedSurrender(Color color) {
|
||||
@@ -88,12 +88,14 @@ public class Console implements GameListener {
|
||||
System.out.println("New position: ");
|
||||
Coordinate end = stringToCoordinate(scanner.nextLine());
|
||||
Command.CommandResult result = sendCommand(new MoveCommand(new Move(start, end)));
|
||||
if (Objects.requireNonNull(result) == Command.CommandResult.Moved) {
|
||||
updateDisplay();
|
||||
return true;
|
||||
}
|
||||
switch (Objects.requireNonNull(result)) {
|
||||
case Command.CommandResult.Moved: return true;
|
||||
case Command.CommandResult.ActionNeeded: updateDisplay(); promotePawn(end); return true;
|
||||
default: System.out.println(result);
|
||||
System.out.println("Move not allowed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
System.out.println(e.getMessage());
|
||||
return false;
|
||||
@@ -152,7 +154,7 @@ public class Console implements GameListener {
|
||||
|
||||
@Override
|
||||
public void gameStarted() {
|
||||
System.out.println("Game start:");
|
||||
System.out.println("Game start!");
|
||||
updateDisplay();
|
||||
}
|
||||
|
||||
@@ -195,10 +197,10 @@ public class Console implements GameListener {
|
||||
for (int j = 0; j < Coordinate.VALUE_MAX; j++) {
|
||||
Piece p = pieceAt(j, i);
|
||||
if ((i+j)%2==0) {
|
||||
string.append(Colors.WHITE_BACKGROUND);
|
||||
string.append(Colors.LIGHT_GRAY_BACKGROUND);
|
||||
}
|
||||
else {
|
||||
string.append(Colors.BLACK_BACKGROUND);
|
||||
string.append(Colors.DARK_GRAY_BACKGROUND);
|
||||
}
|
||||
if (p == null) {
|
||||
string.append(" " + Colors.RESET);
|
||||
@@ -221,24 +223,20 @@ public class Console implements GameListener {
|
||||
Coordinate currentCell = new Coordinate(j, i);
|
||||
Piece p = pieceAt(j, i);
|
||||
if (moves.contains(currentCell)){
|
||||
if ((i + j) % 2 == 0) {
|
||||
string.append(Colors.YELLOW_BACKGROUND);
|
||||
} else {
|
||||
string.append(Colors.RED_BACKGROUND);
|
||||
}
|
||||
} else {
|
||||
if ((i + j) % 2 == 0) {
|
||||
string.append(Colors.WHITE_BACKGROUND);
|
||||
string.append(Colors.LIGHT_GRAY_BACKGROUND);
|
||||
} else {
|
||||
string.append(Colors.BLACK_BACKGROUND);
|
||||
string.append(Colors.DARK_GRAY_BACKGROUND);
|
||||
}
|
||||
}
|
||||
if (p == null) {
|
||||
string.append(" " + Colors.RESET);
|
||||
}
|
||||
else {
|
||||
if (currentCell == piece) {
|
||||
string.append(Colors.RED).append(" ").append(consolePieceName.getString(p)).append(" ").append(Colors.RESET);
|
||||
if (currentCell.equals(piece)) {
|
||||
string.append(Colors.RED_BACKGROUND).append(" ").append(consolePieceName.getString(p)).append(" ").append(Colors.RESET);
|
||||
} else {
|
||||
string.append(" ").append(consolePieceName.getString(p)).append(" ").append(Colors.RESET);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user