Basically, I have this while loop that retrieves the co-ordinates of a button pressed (which is a chess piece) and goes through the loop to see if a move can be made.
However, the co-ordinates of the same chess piece are constantly being fed through so if the piece has no moves available, the same message keeps being displayed over and over again until a different button is pressed, and the same thing happens again if that piece has no moves. How would I go about only printing the same message once each time a piece is clicked?
I tried using a do while loop where the condition in the while loop was only check if the button has moves available if the value of the co-ordinates are different to the ones being fed in. But this made no difference?
while(!correctMove){
do{
fromXCo = s.getFromXInt();
fromYCo = s.getFromYInt();
toXCo = s.getToXInt();
toYCo = s.getToYInt();
p = board.getPiece(fromXCo, fromYCo);
//checks if occupied co-ordinate, if not goes back out the loop and asks again.
if (!board.occupied(fromXCo, fromYCo)){
System.out.println("Please choose occupied co-ordinates \n");
correctMove = false;
}
//checks if the colour is the same as the player's. If not, asks for co-ordinates again.
if (p.getColour() != getPieces().getColour()){
System.out.println("Please move your own pieces \n");
correctMove = false;
}
//tells player their selected piece
System.out.println("Your selected piece is " + p.getChar());
//looks through available moves for piece
moves = p.availableMoves();
//if no moves available, asks for new co-ordinates.
if (moves == null){
System.out.println("No moves available for this piece \n");
correctMove = false;
}
else {
Move found = null;
for( Move m : moves){
//checks if move can be done
if (m.ToX() == toXCo && m.ToY() == toYCo){
//if move is allowed- exit loop
found = m;
correctMove = true;
}
}
if (found == null) {
//if move can't be, ask for new co-ordinates
System.out.println("This move is not legal \n");
correctMove = false;
}
}
}while(fromXCo != s.getFromXInt() && fromYCo != s.getFromYInt() && toXCo != s.getToXInt() && toYCo != s.getToYInt());
}