added getPiece method to return piece into ishiglighted, doesnt work ATM

but i think its because getpiece returns null when starting the game,
the ishiglighted method might not like it
This commit is contained in:
hugomanipoud2 2025-05-20 15:18:59 +02:00
parent 7ab2b45919
commit 8a67fc5aff
2 changed files with 27 additions and 9 deletions

View File

@ -122,7 +122,6 @@ public class Board {
}
public void userTouch(int x, int y) {
if(selectX == -1 && selectY == -1) { // if initial position for select x and y
if(setSelectXY(x,y) == true) { // checks for pieces at the position x and y
selectX = x; //set select x to x
@ -148,7 +147,9 @@ public class Board {
public boolean setSelectXY(int x, int y) { //verify if there is a piece at the coordinates of the point selectX;selectY
boolean isPieceHere = false; // setting bool var
for (Piece piece : pieces) { // iterate trough all pieces
if (piece.getX() == x && piece.getY() == y) {
isPieceHere = !isPieceHere; //chnaging the value to true if a piece is at the coordinates
}
@ -184,9 +185,11 @@ public class Board {
public boolean isHighlighted(int x, int y) {
boolean isAPieceHere = false ; // final return boolean value
PieceType type = null; // type of piece variable that we will get trough a loop, this will determine the pattern of colors
boolean color = true; // color of the piece for pawns that can only go in -y for black and +Y for white
PieceType type = getPiece(x,y).getType(); // type of piece variable that we will get trough a loop, this will determine the pattern of highlights on the board
boolean color = getPiece(x,y).isWhite(); //color of the piece for pawns that can only go in -y for black and +Y for white
for(int i = 1; i < 2;i++)
if(selectX == x && selectY == y+i) {
isAPieceHere = true;
}
@ -194,6 +197,17 @@ public class Board {
}
public Piece getPiece(int x, int y) {
Piece concernedPiece = null; //initialization of piece var
for (Piece piece : pieces) { //iterating through all pieces
if (piece.getX() == x && piece.getY() == y) { // match with coordinates
concernedPiece = piece;
}
}
return concernedPiece; // returns the piece
}
public void undoLastMove() {
//TODO

View File

@ -46,6 +46,10 @@ public class Piece {
this.y = y;
}
//in prevision to change the type of a pawn that could get to the other side of the board
public void setType (PieceType type) {
this.type = type;
}
//idea to add indexes to each pieces
//public int getIndex() {
// return index;