Solved the error in the whatPiece

This commit is contained in:
edwin 2025-05-06 14:06:50 +02:00
parent 28b5df793b
commit 13d1dd4de5
1 changed files with 4 additions and 1 deletions

View File

@ -124,7 +124,7 @@ public class Board {
public int whatPiece(int x, int y) { // method which gives the index (in the pieces array) of the piece at a position x,y
boolean pieceHere = false;
int index = 0;
while (pieceHere == false) {
while (pieceHere == false && index != pieces.size()) {
if((x == pieces.get(index).getX()) && (y == pieces.get(index).getY())){
pieceHere =true;
}
@ -132,6 +132,9 @@ public class Board {
index += 1;
}
}
if(index == pieces.size()) {
index=-1;
}
return index;
}