Hallo diese do while Schleife wird immer zwei Mal aufgerufen, egal ob die Methode changeField true oder false zurückgibt woran liegt das?
Java:
private void playersTurn() {
System.out.println("Spieler ist am Zug.");
villainBoard.print(hideVillainShips);
int[] playerSearch = null;
do {
villainBoard.changeField();
villainBoard.print(true);
}
while (villainBoard.changeField());
Code:
public boolean changeField() {
TreasuryHuntGame test1 = new TreasuryHuntGame();
int[] checkcoordinates = test1.getUserCoordinates();
if (fields[checkcoordinates[0]] [checkcoordinates[1]] == TREASURE) {
fields[checkcoordinates[0]] [checkcoordinates[1]] = HIT;
System.out.println("TREFFER!");
return true;
}
else if (fields[checkcoordinates[0]] [checkcoordinates[1]] == '.') {
fields[checkcoordinates[0]] [checkcoordinates[1]] = '-';
System.out.println("DER GING DANEBEN!");
return false;
}
else {
System.out.println("Daneben");
return false;
}
}