Skip to content

Commit

Permalink
🔧 UPDATE: Add pawn promotion dialogue
Browse files Browse the repository at this point in the history
Added new dialogue for player to choose pawn promotion piece.
  • Loading branch information
GreengagePlum committed May 14, 2023
1 parent f03bc65 commit 658474a
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/main/java/me/erken/efe/chess/controller/GameController.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ private void makeMove(int x, int y, String rank) {
});
fades.add(fade);
fade.play();
} catch (PawnPromotionException e) {
makeMove(x, y, pawnPromotionChoice());
} catch (EndOfGameException e) {
endGame();
} finally {
Expand Down Expand Up @@ -154,6 +156,34 @@ public void selectOrMove(MouseEvent event) {
}
}

private String pawnPromotionChoice() {
// Create an Alert dialog with CONFIRMATION AlertType
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle("Promotion de pion");
alert.setHeaderText("Quelle promotion voulez-vous ?");
alert.setContentText("Faites votre choix de pièce");

// Add two buttons to the Alert dialog
ButtonType buttonTypeQueen = new ButtonType("Dame");
ButtonType buttonTypeRook = new ButtonType("Tour");
ButtonType buttonTypeBishop = new ButtonType("Fou");
ButtonType buttonTypeKnight = new ButtonType("Cavalier");

alert.getButtonTypes().setAll(buttonTypeQueen, buttonTypeRook, buttonTypeBishop, buttonTypeKnight);
Optional<ButtonType> choice = alert.showAndWait();
String result = choice.map(ButtonType::getText).orElse(null);
if (result == null) {
return null;
}
return switch (result) {
case "Dame" -> Queen.class.getSimpleName();
case "Tour" -> Rook.class.getSimpleName();
case "Fou" -> Bishop.class.getSimpleName();
case "Cavalier" -> Knight.class.getSimpleName();
default -> result;
};
}

private void endGame() {
String endCause = Constants.EndGameExplanations.getExplanation(game.endReason());

Expand Down

0 comments on commit 658474a

Please sign in to comment.