„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;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class ManualBot extends Bot {
|
||||
public ManualBot (String[] args){
|
||||
super(args);
|
||||
}
|
||||
|
||||
public static void main (String[] args){
|
||||
ManualBot manualbot = new ManualBot(args);
|
||||
manualbot.run();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected char nextMove(View view) throws Exception {
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
char move = scanner.nextLine().charAt(0);
|
||||
|
||||
switch (move) {
|
||||
case 'w':
|
||||
case's':
|
||||
case'a':
|
||||
case'd':
|
||||
case'q':
|
||||
return move;
|
||||
default:
|
||||
System.out.println("Falsche Taste. Bitte geben sie w,s,a,d,q ein danke.");
|
||||
return nextMove(view);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
package bot;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class ManualBot extends Bot {
|
||||
public ManualBot(String[] args) {
|
||||
super(args);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
ManualBot manualBot = new ManualBot(args);
|
||||
manualBot.run();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected char nextMove(View view) throws Exception {
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
char move;
|
||||
|
||||
do {
|
||||
System.out.println("Bitte geben Sie einen Steuerbefehl ein (w, s, a, d, q): ");
|
||||
move = scanner.nextLine().toLowerCase().charAt(0);
|
||||
} while (!isValidMove(move));
|
||||
|
||||
return move;
|
||||
}
|
||||
|
||||
private boolean isValidMove(char move) {
|
||||
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