From 63193fde19277c3e8cf2f9e8b8e9c6b4ef51d420 Mon Sep 17 00:00:00 2001 From: Tanja Herche Date: Mon, 6 Feb 2023 10:30:55 +0100 Subject: [PATCH] refactoring: common String locationName --- .../org/bitbiome/commands/TravelCommand.java | 38 +++++++++++++------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/bitbiome/commands/TravelCommand.java b/src/main/java/org/bitbiome/commands/TravelCommand.java index 91fe7cd..7df3aa3 100644 --- a/src/main/java/org/bitbiome/commands/TravelCommand.java +++ b/src/main/java/org/bitbiome/commands/TravelCommand.java @@ -13,11 +13,19 @@ import java.util.Scanner; public class TravelCommand implements CommandAPI { + public void exittravelCommand() { + System.out.println(Colors.ANSI_BLUE + "Du hast dein Travel-Pad weggesteckt." + Colors.ANSI_RESET); + } + + public void travelCommand() { + + } @Override public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine travelEngine) { System.out.println(Colors.ANSI_BLUE + "Du hast dein Travel-Pad gezückt. Wohin möchtest du reisen?" + Colors.ANSI_RESET); JSONArray locations = travelEngine.getLocationList(); + String locationName; String locationWueste = locations.getJSONObject(5).getString("name"); String locationGruenland = locations.getJSONObject(4).getString("name"); String locationWinterland = locations.getJSONObject(2).getString("name"); @@ -27,67 +35,73 @@ public class TravelCommand implements CommandAPI { if (travelEngine.getPlayer().getLocation().getName().equalsIgnoreCase("Wald")) { System.out.println("- " + locationStrand + "\n" + "- " + locationGruenland + "\n" + "- " + locationBerge); - String locationName = scanner.nextLine(); + locationName = scanner.nextLine(); if (travelEngine.locationExistsWald(locationName)) { travelEngine.travelTo(new Location(locationName, new ArrayList(), new ArrayList())); System.out.println(Colors.ANSI_BLUE + "Du bist nun hierhin gereist: " + locationName + "\n" + Colors.ANSI_RESET); } else { - System.out.println(Colors.ANSI_BLUE + "Du hast dein Travel-Pad weggesteckt." + Colors.ANSI_RESET); + exittravelCommand(); + return; } } else if (travelEngine.getPlayer().getLocation().getName().equalsIgnoreCase("Strand")) { System.out.println("- " + locationWueste + "\n" + "- " + locationWald); - String locationName = scanner.nextLine(); + locationName = scanner.nextLine(); if (travelEngine.locationExistsStrand(locationName)) { travelEngine.travelTo(new Location(locationName, new ArrayList(), new ArrayList())); System.out.println(Colors.ANSI_BLUE + "Du bist nun hierhin gereist: " + locationName + "\n" + Colors.ANSI_RESET); } else { - System.out.println(Colors.ANSI_BLUE + "Du hast dein Travel-Pad weggesteckt." + Colors.ANSI_RESET); + exittravelCommand(); + return; } } else if (travelEngine.getPlayer().getLocation().getName().equalsIgnoreCase("Gruenland")) { System.out.println("- " + locationWueste + "\n" + "- " + locationWald + "\n" + "- " + locationWinterland); - String locationName = scanner.nextLine(); + locationName = scanner.nextLine(); if (travelEngine.locationExistsGruenland(locationName)) { travelEngine.travelTo(new Location(locationName, new ArrayList(), new ArrayList())); System.out.println(Colors.ANSI_BLUE + "Du bist nun hierhin gereist: " + locationName + "\n" + Colors.ANSI_RESET); } else { - System.out.println(Colors.ANSI_BLUE + "Du hast dein Travel-Pad weggesteckt." + Colors.ANSI_RESET); + exittravelCommand(); + return; } } else if (travelEngine.getPlayer().getLocation().getName().equalsIgnoreCase("Berge")) { System.out.println("- " + locationWald + "\n" + "- " + locationWinterland); - String locationName = scanner.nextLine(); + locationName = scanner.nextLine(); if (travelEngine.locationExistsBerge(locationName)) { travelEngine.travelTo(new Location(locationName, new ArrayList(), new ArrayList())); System.out.println(Colors.ANSI_BLUE + "Du bist nun hierhin gereist: " + locationName + "\n" + Colors.ANSI_RESET); } else { - System.out.println(Colors.ANSI_BLUE + "Du hast dein Travel-Pad weggesteckt." + Colors.ANSI_RESET); + exittravelCommand(); + return; } } else if (travelEngine.getPlayer().getLocation().getName().equalsIgnoreCase("Winterland")) { System.out.println("- " + locationGruenland + "\n" + "- " + locationBerge); - String locationName = scanner.nextLine(); + locationName = scanner.nextLine(); if (travelEngine.locationExistsWinterland(locationName)) { travelEngine.travelTo(new Location(locationName, new ArrayList(), new ArrayList())); System.out.println(Colors.ANSI_BLUE + "Du bist nun hierhin gereist: " + locationName + "\n" + Colors.ANSI_RESET); } else { - System.out.println(Colors.ANSI_BLUE + "Du hast dein Travel-Pad weggesteckt." + Colors.ANSI_RESET); + exittravelCommand(); + return; } } else if (travelEngine.getPlayer().getLocation().getName().equalsIgnoreCase("Wueste")) { System.out.println("- " + locationStrand + "\n" + "- " + locationGruenland); - String locationName = scanner.nextLine(); + locationName = scanner.nextLine(); if (travelEngine.locationExistsWueste(locationName)) { travelEngine.travelTo(new Location(locationName, new ArrayList(), new ArrayList())); System.out.println(Colors.ANSI_BLUE + "Du bist nun hierhin gereist: " + locationName + "\n" + Colors.ANSI_RESET); } else { - System.out.println(Colors.ANSI_BLUE + "Du hast dein Travel-Pad weggesteckt." + Colors.ANSI_RESET); + exittravelCommand(); + return; } } }