Compare commits
3 Commits
5756f21914
...
97b0a4ad00
| Author | SHA1 | Date |
|---|---|---|
|
|
97b0a4ad00 | |
|
|
e085f3393f | |
|
|
315c8477b0 |
|
|
@ -102,6 +102,42 @@ public class Board {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*public void movePiece(int fromX, int fromY, int toX, int toY) {
|
||||||
|
Piece piece = board.getPieceAt(fromX, fromY);
|
||||||
|
if (piece == null) return;
|
||||||
|
|
||||||
|
// --- En Passant ---
|
||||||
|
SpecialMoves special = new SpecialMoves(piece, board);
|
||||||
|
boolean isEnPassant = special.isEnpassant(fromX, fromY, toX, toY);
|
||||||
|
|
||||||
|
// --- Move the piece
|
||||||
|
board.setPieceAt(toX, toY, piece);
|
||||||
|
board.setPieceAt(fromX, fromY, null);
|
||||||
|
piece.setX(toX);
|
||||||
|
piece.setY(toY);
|
||||||
|
|
||||||
|
// --- Reset all pawns' en passant eligibility
|
||||||
|
for (int i = 0; i < 8; i++) {
|
||||||
|
for (int j = 0; j < 8; j++) {
|
||||||
|
Piece p = board.getPieceAt(i, j);
|
||||||
|
if (p != null && p.getType() == PieceType.Pawn) {
|
||||||
|
p.setEnPassantEligible(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- If current pawn moved 2 steps forward, set it eligible for en passant
|
||||||
|
if (piece.getType() == PieceType.Pawn && Math.abs(toY - fromY) == 2) {
|
||||||
|
piece.setEnPassantEligible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- En Passant message
|
||||||
|
if (isEnPassant) {
|
||||||
|
System.out.println("En Passant captured successfully!");
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
|
|
||||||
public void cleanBoard() {
|
public void cleanBoard() {
|
||||||
pieces.clear();
|
pieces.clear();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,16 @@ public class Piece {
|
||||||
private boolean isWhite;
|
private boolean isWhite;
|
||||||
private PieceType type;
|
private PieceType type;
|
||||||
|
|
||||||
|
/*private boolean enPassantEligible = false;
|
||||||
|
|
||||||
|
public boolean isEnPassantEligible() {
|
||||||
|
return enPassantEligible;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEnPassantEligible(boolean eligible) {
|
||||||
|
this.enPassantEligible = eligible;
|
||||||
|
}
|
||||||
|
*/
|
||||||
public Piece(int x, int y, boolean isWhite, PieceType type) {
|
public Piece(int x, int y, boolean isWhite, PieceType type) {
|
||||||
this.x=x;
|
this.x=x;
|
||||||
this.y=y;
|
this.y=y;
|
||||||
|
|
|
||||||
|
|
@ -57,4 +57,35 @@ public class SpecialMoves {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}*/
|
}
|
||||||
|
package backend;
|
||||||
|
|
||||||
|
public class SpecialMoves {
|
||||||
|
|
||||||
|
private Piece piece;
|
||||||
|
private Board board;
|
||||||
|
|
||||||
|
public SpecialMoves(Piece piece, Board board) {
|
||||||
|
this.piece = piece;
|
||||||
|
this.board = board;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Call this when trying to move a pawn to check for en passant
|
||||||
|
public boolean isEnpassant(int fromX, int fromY, int toX, int toY) {
|
||||||
|
if (piece.getType() != PieceType.Pawn) return false;
|
||||||
|
|
||||||
|
boolean isWhite = piece.isWhite();
|
||||||
|
|
||||||
|
// En passant capture happens diagonally
|
||||||
|
int dx = toX - fromX;
|
||||||
|
int dy = toY - fromY;
|
||||||
|
|
||||||
|
if (Math.abs(dx) != 1 || (isWhite && dy != -1) || (!isWhite && dy != 1)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check the adjacent piece
|
||||||
|
Piece sidePawn = board.getPieceAt(toX, fromY);
|
||||||
|
if (sidePawn == null || sidePawn.getType() != PieceType.Pawn || sidePawn.isWhite() == isWhite) {
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
@ -80,7 +80,28 @@ public class JPanelChessBoard extends JPanel {
|
||||||
@Override
|
@Override
|
||||||
protected void paintComponent(Graphics g) {
|
protected void paintComponent(Graphics g) {
|
||||||
super.paintComponent(g);
|
super.paintComponent(g);
|
||||||
this.setBackground(Color.black);
|
this.setBackground(new Color(170, 51, 106));
|
||||||
|
|
||||||
|
if (myGame == null) {
|
||||||
|
// Display title before game starts
|
||||||
|
g.setColor(Color.WHITE);
|
||||||
|
g.setFont(g.getFont().deriveFont(48f)); // larger font size
|
||||||
|
String title = "Chess Project";
|
||||||
|
int stringWidth = g.getFontMetrics().stringWidth(title);
|
||||||
|
int x = (getWidth() - stringWidth) / 2;
|
||||||
|
int y = getHeight() / 2;
|
||||||
|
g.drawString(title, x, y);
|
||||||
|
|
||||||
|
g.setFont(g.getFont().deriveFont(24f)); // Smaller font for subtitle
|
||||||
|
String subtitle = "Groupe 2A5";
|
||||||
|
int subtitleWidth = g.getFontMetrics().stringWidth(subtitle);
|
||||||
|
int x2 = (getWidth() - subtitleWidth) / 2;
|
||||||
|
int y2 = y + 40; // 40 pixels below the title, adjust spacing if needed
|
||||||
|
g.drawString(subtitle, x2, y2);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if(pieceSelectorMode) {
|
if(pieceSelectorMode) {
|
||||||
g.drawImage(
|
g.drawImage(
|
||||||
spriteSheet,
|
spriteSheet,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue