diff --git a/ManualBot.java b/ManualBot.java index 737e2da..9d2dd74 100644 --- a/ManualBot.java +++ b/ManualBot.java @@ -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; + } + } +}