Habe diese Aufgabe fast geschaft. Jedoch nicht ganz richtig.
Das Problem, dass die Ausgangsposition soll in der Mitte des Labyrinths sein. Bei mir fängt von [0][0] an. Wie kann ich das ändern?
Ich bedanke mich im Voraus für Bemühen und würde mich über jede Antwort sehr freuen )
Code:
public class LabyrinthChar {
public static void main(String[] args) {
............
}
public static boolean navigate(char [][] lab, int i, int j){
boolean weg = true;
if(i == lab.length-1 || j == lab[0].length-1){
return weg;
}else{
if (lab[i][j+1]== ' '){
lab[i][j+1]= '*';
if(navigate(lab,i,j+1)) return true;
}
if (lab[i+1][j]==' '){
lab[i+1][j]='*';
if(navigate(lab,i+1,j)) return true;
}
if (lab[i][j-1]==' '){
lab[i][j-1]='*';
if(navigate(lab,i,j-1)) return true;
}
if (lab[i-1][j]==' '){
lab[i-1][j]='*';
if(navigate(lab,i-1,j)) return true;
}
}
return false;
}
}
Das Problem, dass die Ausgangsposition soll in der Mitte des Labyrinths sein. Bei mir fängt von [0][0] an. Wie kann ich das ändern?
Ich bedanke mich im Voraus für Bemühen und würde mich über jede Antwort sehr freuen )