diff --git a/OOP_2B1_Project/src/backend/Board.java b/OOP_2B1_Project/src/backend/Board.java index cbe8c9e..a27354e 100644 --- a/OOP_2B1_Project/src/backend/Board.java +++ b/OOP_2B1_Project/src/backend/Board.java @@ -3,6 +3,8 @@ package backend; import java.util.ArrayList; import java.util.LinkedList; +import javax.swing.JOptionPane; + public class Board { private KingCheck kingCheck = new KingCheck(); private int width = 8; @@ -151,22 +153,45 @@ public class Board { } } } - + board.get(this.ym).set(this.xm,null); this.setPiece(x,y,pieceToMove.getType(),pieceToMove.isWhite()); Piece movedPiece = this.getPiece(x, y); if (movedPiece instanceof Pawn) { int promotionRow = movedPiece.isWhite() ? 0 : 7; if (y == promotionRow) { - // Replace pawn with promoted piece -// System.out.println() - this.setPiece(x,y,PieceType.Queen,pieceToMove.isWhite()); + Object[] choices = { "Queen", "Rook", "Bishop", "Knight" }; + String selected = (String) JOptionPane.showInputDialog( + null, + "Choose a piece for promotion:", + "Pawn Promotion", + JOptionPane.PLAIN_MESSAGE, + null, + choices, + "Queen" + ); + + Piece promoted; + switch (selected) { + case "Rook": + promoted = new Rook(x, y, false); + break; + case "Bishop": + promoted = new Bishop(x, y, false); + break; + case "Knight": + promoted = new Knight(x, y, false); + break; + default: + promoted = new Queen(x, y, false); + } + board.get(y).set(x, promoted); + this.setPiece(x,y,promoted.getType(),pieceToMove.isWhite()); // You can replace Queen with any piece type as needed } } if (movedPiece != null) { movedPiece.setMoved(true); } - board.get(this.ym).set(this.xm,null); } } diff --git a/OOP_2B1_Project/src/windowInterface/MyInterface.java b/OOP_2B1_Project/src/windowInterface/MyInterface.java index 08fb41d..054cd68 100644 --- a/OOP_2B1_Project/src/windowInterface/MyInterface.java +++ b/OOP_2B1_Project/src/windowInterface/MyInterface.java @@ -275,6 +275,11 @@ public class MyInterface extends JFrame { public void showGameOverMessage(String message) { JOptionPane.showMessageDialog(this, message, "Game Over", JOptionPane.INFORMATION_MESSAGE); + game.toggleAI(false); + game.toggleAI(true); + chckbxWhiteAI.setSelected(false); + chckbxBlackAI.setSelected(false); + } private int askDifficulty() { Object[] options = {"Easy", "Medium", "Hard"};