„ManualBot.java“ ändern
Ich habe die manuelle Steugerung durch Unterklasse ManuelBot erlaubt. Eingabe „w“ - Vorwärts Eingabe „s“ - Rückwärts Eingabe „a“- Linksdrehung Eingabe „d“ - Rechtsdrehung Eingabe „q“ -Abbruch der Verbindung
This commit is contained in:
parent
3f64df6fc4
commit
eae8ae3f64
@ -1,35 +1,41 @@
|
|||||||
package bot;
|
package bot;
|
||||||
|
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class ManualBot extends Bot {
|
public class ManualBot extends Bot {
|
||||||
public ManualBot (String[] args){
|
public ManualBot(String[] args) {
|
||||||
super(args);
|
super(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main (String[] args){
|
public static void main(String[] args) {
|
||||||
ManualBot manualbot = new ManualBot(args);
|
ManualBot manualBot = new ManualBot(args);
|
||||||
manualbot.run();
|
manualBot.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected char nextMove(View view) throws Exception {
|
protected char nextMove(View view) throws Exception {
|
||||||
Scanner scanner = new Scanner(System.in);
|
Scanner scanner = new Scanner(System.in);
|
||||||
char move = scanner.nextLine().charAt(0);
|
char move;
|
||||||
|
|
||||||
switch (move) {
|
do {
|
||||||
case 'w':
|
System.out.println("Bitte geben Sie einen Steuerbefehl ein (w, s, a, d, q): ");
|
||||||
case's':
|
move = scanner.nextLine().toLowerCase().charAt(0);
|
||||||
case'a':
|
} while (!isValidMove(move));
|
||||||
case'd':
|
|
||||||
case'q':
|
return move;
|
||||||
return move;
|
}
|
||||||
default:
|
|
||||||
System.out.println("Falsche Taste. Bitte geben sie w,s,a,d,q ein danke.");
|
private boolean isValidMove(char move) {
|
||||||
return nextMove(view);
|
switch (move) {
|
||||||
}
|
case 'w':
|
||||||
}
|
case 's':
|
||||||
}
|
case 'a':
|
||||||
|
case 'd':
|
||||||
|
case 'q':
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
System.out.println("Falsche Taste. Bitte geben Sie w, s, a, d oder q ein.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user