created specialMOves class, pawnpromotion doesnt work idk

This commit is contained in:
hugomanipoud2 2025-05-22 17:36:30 +02:00
parent 57d39fff7d
commit 99c1f81fee
2 changed files with 6 additions and 11 deletions

View File

@ -135,7 +135,7 @@ public class Board {
public void userTouch(int x, int y) {
if(selectX == -1 && selectY == -1) { // if initial position for select x and y
if(isAPieceThere(x,y) == true) { // checks for pieces at the position x and y
if(getPiece(x,y).isWhite() == isTurnWhite()) {
if(getPiece(x,y).isWhite() == isTurnWhite()) { // check if its the turn of the piece selected (check if its turn for black or white)
selectX = x; //set select x to x
selectY = y; // same with y
}

View File

@ -5,12 +5,14 @@ import java.util.ArrayList;
public class Move {
private ArrayList<Piece> pieces;
private Board board;
private SpecialMoves specialMoves;
public Move(ArrayList<Piece> pieces, Board board) { // constructor of move class, it has acces to the same array list as board class
// as the name of the arraylist is the same and its taking it as an input in the
// board class
this.pieces = pieces; // this is the array list
this.board = board; // creation of an acces to board methods, for setselectXY in particular
this.specialMoves = new SpecialMoves(pieces, board);
}
@ -34,12 +36,7 @@ public class Move {
if (board.isAPieceThere(toX, toY)){//checking if a piece is at the arrival coordinates
needPieceDeletion(toX, toY); //if a piece is at arrival coord, remove the piece
}
if(type == PieceType.Pawn && color == true && toY == 0) {
pawnPromotion(movingPiece);
}
if(type == PieceType.Pawn && color == false && toY == 7) {
pawnPromotion(movingPiece);
}
specialMoves.pawnPromotion(movingPiece);
movingPiece.setX(toX); // change coordinates to the new coordinate
movingPiece.setY(toY);
board.setTurnNb(turnNb + 1);
@ -59,9 +56,7 @@ public class Move {
}
}
}
private void pawnPromotion(Piece piece) {
piece.setType(PieceType.Queen);
}
private int isFirstPawnMove (int yCord) {
if (yCord == 6 || yCord == 1 ) {
return 3;