From 99c1f81feefc63fec69936d5930cbce9813c76bc Mon Sep 17 00:00:00 2001 From: hugomanipoud2 Date: Thu, 22 May 2025 17:36:30 +0200 Subject: [PATCH] created specialMOves class, pawnpromotion doesnt work idk --- OOP_3B5_Project/src/backend/Board.java | 2 +- OOP_3B5_Project/src/backend/Move.java | 15 +++++---------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/OOP_3B5_Project/src/backend/Board.java b/OOP_3B5_Project/src/backend/Board.java index 492252a..8d6c0ec 100644 --- a/OOP_3B5_Project/src/backend/Board.java +++ b/OOP_3B5_Project/src/backend/Board.java @@ -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 } diff --git a/OOP_3B5_Project/src/backend/Move.java b/OOP_3B5_Project/src/backend/Move.java index 9edb6d4..2336cc3 100644 --- a/OOP_3B5_Project/src/backend/Move.java +++ b/OOP_3B5_Project/src/backend/Move.java @@ -5,12 +5,14 @@ import java.util.ArrayList; public class Move { private ArrayList pieces; private Board board; + private SpecialMoves specialMoves; public Move(ArrayList 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); } @@ -33,13 +35,8 @@ 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;