diff --git a/OOP_3B5_Project/src/backend/Move.java b/OOP_3B5_Project/src/backend/Move.java index 7895688..1410a89 100644 --- a/OOP_3B5_Project/src/backend/Move.java +++ b/OOP_3B5_Project/src/backend/Move.java @@ -60,28 +60,25 @@ public class Move { private void pawnPromotion(Piece piece) { piece.setType(PieceType.Queen); } - + private int isFirstPawnMove (int yCord) { + if (yCord == 6 || yCord == 1 ) { + return 3; + } + return 2; + } public boolean isPawnMoveValid(int x, int y, boolean color, int selectX, int selectY, int yCord) { if (color == true) { - int k = 2; - if(yCord == 6) { //this condition is specific to the pawn, pawns can move 2 cases for their first move, but once they moved once they can move only 1 case. as they cant go back, this simple condition allows for regulation of this rule - k = 3; - }else { - k = 2; - } - for(int i = 1; i < k;i++) { // this loop iterates from 1 to 3 as pawns for their first move can go forward 2 slots. removing 0 let the is selected function do its job - if(selectX == x && selectY == y+i) { // this loop iterates 2 times trough the for loop, giving multiples coordinates to highlight ( here : (x;y+1)&(x;y+2)) - return true; //set the boolean var to true + int k = isFirstPawnMove(yCord); // determine if k should be 3 or 2 to begin with + for(int i = 1; i < k;i++) { // this loop iterates from 1 to 3 as pawns for their first move can go forward 2 slots. removing 0 let the is selected function do its job + if (board.getPiece(selectX , selectY + i) != null) { + if(selectX == x && selectY == y+i) { // this loop iterates 2 times trough the for loop, giving multiples coordinates to highlight ( here : (x;y+1)&(x;y+2)) + return true; //set the boolean var to true + } } } } else { //if color == false so for black pieces - int k = 2; - if(yCord == 1) { - k = 3; - }else { - k = 2 ; - } + int k = isFirstPawnMove (yCord); for(int i = 1; i < k;i++) { if(selectX == x && selectY == y-i) {