From 5c27832805b51faa660e52179c5597acd7b094fa Mon Sep 17 00:00:00 2001 From: hugomanipoud2 Date: Thu, 22 May 2025 14:58:28 +0200 Subject: [PATCH] working on pawn movements, removed some spaghetti using the K variable used on other movement methods --- OOP_3B5_Project/src/backend/Board.java | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/OOP_3B5_Project/src/backend/Board.java b/OOP_3B5_Project/src/backend/Board.java index 2672c9d..38a0ee4 100644 --- a/OOP_3B5_Project/src/backend/Board.java +++ b/OOP_3B5_Project/src/backend/Board.java @@ -213,22 +213,21 @@ public class Board { // from here its spaghetti but its works ! i'll explain one, its the same logic for all of them if(type == PieceType.Pawn && color == true) { //check type of piece, here its pawn and they can only move forward so i check the type too + 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 - for(int i = 1; i < 3;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)) - isAPieceHere = true; //set the boolean var to true + 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)) + isAPieceHere = true; //set the boolean var to true } } - - }else { - for(int i = 1; i < 2;i++) { - if(selectX == x && selectY == y+i) { - isAPieceHere = true; - } - } - } - } else if (type == PieceType.Pawn && color == false) { + + + else if (type == PieceType.Pawn && color == false) { if(yCord == 1) { for(int i = 1; i < 3;i++) {