Command refactor
This commit is contained in:
@@ -55,7 +55,7 @@ public class Console implements GameListener {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playerTurn(Color color) {
|
||||
public void onPlayerTurn(Color color) {
|
||||
System.out.println(Colors.RED + "Player turn: " + color + Colors.RESET);
|
||||
boolean endTurn;
|
||||
do {
|
||||
@@ -73,7 +73,7 @@ public class Console implements GameListener {
|
||||
};
|
||||
} while (!endTurn);
|
||||
System.out.println(Colors.RED + "Turn ended." + Colors.RESET);
|
||||
updateDisplay();
|
||||
onBoardUpdate();
|
||||
}
|
||||
|
||||
private boolean playerPickedSurrender(Color color) {
|
||||
@@ -89,10 +89,9 @@ public class Console implements GameListener {
|
||||
Coordinate end = stringToCoordinate(scanner.nextLine());
|
||||
Command.CommandResult result = sendCommand(new MoveCommand(new Move(start, end)));
|
||||
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.");
|
||||
case Command.CommandResult.Moved:
|
||||
case Command.CommandResult.ActionNeeded: return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -125,46 +124,45 @@ public class Console implements GameListener {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void winnerIs(Color color) {
|
||||
public void onWin(Color color) {
|
||||
System.out.println(Colors.RED + "Victory of player " + color + Colors.RESET);
|
||||
gameEnded();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void kingIsInCheck() {
|
||||
public void onKingInCheck() {
|
||||
System.out.println(Colors.RED + "Check!" + Colors.RESET);
|
||||
// todo
|
||||
}
|
||||
|
||||
@Override
|
||||
public void kingIsInMat() {
|
||||
public void onKingInMat() {
|
||||
System.out.println(Colors.RED + "Checkmate!" + Colors.RESET);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void patSituation() {
|
||||
public void onPatSituation() {
|
||||
// todo
|
||||
gameEnded();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hasSurrendered(Color color) {
|
||||
public void onSurrender(Color color) {
|
||||
System.out.println("The " + color + " player has surrendered!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void gameStarted() {
|
||||
public void onGameStart() {
|
||||
System.out.println("Game start!");
|
||||
updateDisplay();
|
||||
onBoardUpdate();
|
||||
}
|
||||
|
||||
public void gameEnded(){
|
||||
@Override
|
||||
public void onGameEnd() {
|
||||
System.out.println("Thank you for playing!");
|
||||
this.commandExecutor.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void promotePawn(Coordinate pieceCoords) {
|
||||
public void onPromotePawn(Coordinate pieceCoords) {
|
||||
System.out.println("The pawn on the " + pieceCoords + " coordinates needs to be promoted.");
|
||||
System.out.println("Enter 'B' to promote it into a Bishop, 'N' for a Knight, 'Q' for a Queen, 'R' for a Rook.");
|
||||
boolean valid = false;
|
||||
@@ -189,7 +187,7 @@ public class Console implements GameListener {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDisplay() {
|
||||
public void onBoardUpdate() {
|
||||
StringBuilder string = new StringBuilder();
|
||||
string.append(" a b c d e f g h \n");
|
||||
for (int i = 0; i < Coordinate.VALUE_MAX; i++) {
|
||||
@@ -246,4 +244,12 @@ public class Console implements GameListener {
|
||||
}
|
||||
System.out.println(string);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMove(Move move) {}
|
||||
|
||||
@Override
|
||||
public void onMoveNotAllowed(Move move) {
|
||||
System.out.println("Move not allowed.");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user