This commit is contained in:
@@ -38,6 +38,12 @@ public class Console extends GameAdapter implements CommandSender {
|
||||
this(commandExecutor, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate a string containing chess coordinates (such as "a1" or "d6") to coordinates.
|
||||
* @param coordinates the string to translate
|
||||
* @return the coordinates of the cell
|
||||
* @throws Exception if the string is not valid
|
||||
*/
|
||||
public Coordinate stringToCoordinate(String coordinates) throws Exception {
|
||||
char xPos = coordinates.charAt(0);
|
||||
char yPos = coordinates.charAt(1);
|
||||
@@ -56,6 +62,9 @@ public class Console extends GameAdapter implements CommandSender {
|
||||
return new Coordinate(x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Open a dialog so the user can, during their turn, move a piece, show move previews, or surrender.
|
||||
*/
|
||||
@Override
|
||||
public void onPlayerTurn(Color color, boolean undone) {
|
||||
if (!captureInput)
|
||||
@@ -90,6 +99,11 @@ public class Console extends GameAdapter implements CommandSender {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ask the user to pick a move
|
||||
* @param color the color of the player
|
||||
* @return true if there has been a move, false otherwise
|
||||
*/
|
||||
public boolean playerPickedMove(Color color) {
|
||||
try {
|
||||
System.out.println("Piece to move, or \"castling\" for a castling");
|
||||
@@ -113,6 +127,11 @@ public class Console extends GameAdapter implements CommandSender {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ask the user to pick a piece, and show its potential moves
|
||||
* @param color
|
||||
* @return
|
||||
*/
|
||||
private boolean playerPickedShowMoves(Color color) {
|
||||
try {
|
||||
System.out.println("Piece to examine: ");
|
||||
@@ -168,6 +187,10 @@ public class Console extends GameAdapter implements CommandSender {
|
||||
this.executor.shutdown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Open the dialog to promote a pawn.
|
||||
* @param pieceCoords the coordinates of the pawn to promote
|
||||
*/
|
||||
@Override
|
||||
public void onPromotePawn(Coordinate pieceCoords) {
|
||||
System.out.println("The pawn on the " + pieceCoords + " coordinates needs to be promoted.");
|
||||
@@ -195,6 +218,9 @@ public class Console extends GameAdapter implements CommandSender {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Update and print the board in the console.
|
||||
*/
|
||||
@Override
|
||||
public void onBoardUpdate() {
|
||||
if (!this.captureInput)
|
||||
@@ -222,6 +248,11 @@ public class Console extends GameAdapter implements CommandSender {
|
||||
System.out.flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the possible moves of a piece.
|
||||
* @param piece
|
||||
* @param moves
|
||||
*/
|
||||
public void displayMoves(Coordinate piece, List<Coordinate> moves) {
|
||||
StringBuilder string = new StringBuilder();
|
||||
string.append(" a b c d e f g h \n");
|
||||
@@ -265,6 +296,10 @@ public class Console extends GameAdapter implements CommandSender {
|
||||
System.out.println("Repeated positions!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Open different dialogs according to which castling is allowed.
|
||||
* @return true if a castling was played, false otherwise
|
||||
*/
|
||||
private boolean onAskedCastling() {
|
||||
return switch (getAllowedCastlings()) {
|
||||
case Small -> onSmallCastling();
|
||||
@@ -277,6 +312,10 @@ public class Console extends GameAdapter implements CommandSender {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Ask the user to confirm a small castling.
|
||||
* @return true if the castling was played, false otherwise
|
||||
*/
|
||||
private boolean onSmallCastling() {
|
||||
System.out.println("Small castling allowed. Confirm with \"y\":");
|
||||
String answer = scanner.nextLine();
|
||||
@@ -287,6 +326,10 @@ public class Console extends GameAdapter implements CommandSender {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ask the user to confirm a big castling.
|
||||
* @return true if the castling was played, false otherwise
|
||||
*/
|
||||
private boolean onBigCastling() {
|
||||
System.out.println("Big castling allowed. Confirm with \"y\":");
|
||||
String answer = scanner.nextLine();
|
||||
@@ -297,6 +340,10 @@ public class Console extends GameAdapter implements CommandSender {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ask the user to pick a castling when both are allowed.
|
||||
* @return true if a castling was played, false otherwise
|
||||
*/
|
||||
private boolean onBothCastling() {
|
||||
System.out.println("Both castlings allowed. Pick \"s\" to play a castling, \"b\" to play a big castling.");
|
||||
String answer = scanner.nextLine();
|
||||
|
||||
Reference in New Issue
Block a user