color changes in console + promotion

This commit is contained in:
Janet-Doe
2025-04-13 00:56:44 +02:00
parent 39c289cc47
commit 9f44548843
3 changed files with 38 additions and 34 deletions

View File

@@ -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;
}
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);
}
string.append(Colors.YELLOW_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);
}