promotion update
This commit is contained in:
parent
ebf8687fa5
commit
13ec9fb4e8
|
|
@ -3,6 +3,8 @@ package backend;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
|
|
||||||
public class Board {
|
public class Board {
|
||||||
private KingCheck kingCheck = new KingCheck();
|
private KingCheck kingCheck = new KingCheck();
|
||||||
private int width = 8;
|
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());
|
this.setPiece(x,y,pieceToMove.getType(),pieceToMove.isWhite());
|
||||||
Piece movedPiece = this.getPiece(x, y);
|
Piece movedPiece = this.getPiece(x, y);
|
||||||
if (movedPiece instanceof Pawn) {
|
if (movedPiece instanceof Pawn) {
|
||||||
int promotionRow = movedPiece.isWhite() ? 0 : 7;
|
int promotionRow = movedPiece.isWhite() ? 0 : 7;
|
||||||
if (y == promotionRow) {
|
if (y == promotionRow) {
|
||||||
// Replace pawn with promoted piece
|
Object[] choices = { "Queen", "Rook", "Bishop", "Knight" };
|
||||||
// System.out.println()
|
String selected = (String) JOptionPane.showInputDialog(
|
||||||
this.setPiece(x,y,PieceType.Queen,pieceToMove.isWhite());
|
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
|
// You can replace Queen with any piece type as needed
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (movedPiece != null) {
|
if (movedPiece != null) {
|
||||||
movedPiece.setMoved(true);
|
movedPiece.setMoved(true);
|
||||||
}
|
}
|
||||||
board.get(this.ym).set(this.xm,null);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -275,6 +275,11 @@ public class MyInterface extends JFrame {
|
||||||
|
|
||||||
public void showGameOverMessage(String message) {
|
public void showGameOverMessage(String message) {
|
||||||
JOptionPane.showMessageDialog(this, message, "Game Over", JOptionPane.INFORMATION_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() {
|
private int askDifficulty() {
|
||||||
Object[] options = {"Easy", "Medium", "Hard"};
|
Object[] options = {"Easy", "Medium", "Hard"};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue