working on pawn movements, removed some spaghetti using the K variable

used on other movement methods
This commit is contained in:
hugomanipoud2 2025-05-22 14:58:28 +02:00
parent 189c7cb218
commit 5c27832805
1 changed files with 11 additions and 12 deletions

View File

@ -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++) {