Compare commits

..

3 Commits

Author SHA1 Message Date
leahb 97b0a4ad00 Welcome screen 2025-05-18 16:09:06 +02:00
leahb e085f3393f Merge branch 'master' of https://gitarero.ecam.fr/louise.berteloot/OOP_2A5_Project.git 2025-05-13 16:27:21 +02:00
leahb 315c8477b0 attempt en passant 2025-05-13 16:27:06 +02:00
4 changed files with 100 additions and 3 deletions

View File

@ -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() {
pieces.clear();
}

View File

@ -6,7 +6,16 @@ public class Piece {
private boolean isWhite;
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) {
this.x=x;
this.y=y;

View File

@ -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) {
*/

View File

@ -80,7 +80,28 @@ public class JPanelChessBoard extends JPanel {
@Override
protected void paintComponent(Graphics 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) {
g.drawImage(
spriteSheet,