diff --git a/Java-Knight/src/main/java/org/project/Main.java b/Java-Knight/src/main/java/org/project/Main.java index d2d89a9..85645a1 100644 --- a/Java-Knight/src/main/java/org/project/Main.java +++ b/Java-Knight/src/main/java/org/project/Main.java @@ -121,7 +121,7 @@ public class Main { } break; case 2: - currentLocation = moveToLocation(scanner, currentLocation); + currentLocation = moveToLocation(scanner, currentLocation, player); if (!currentLocation.hasEnemy()) { spawnRandomEnemy(currentLocation, random); } @@ -190,16 +190,19 @@ public class Main { } } - private static Location moveToLocation(Scanner scanner, Location current) { - System.out.println("Choose a location to move to:"); - for (int i = 0; i < locations.size(); i++) { - String prefix = locations.get(i).equals(current) ? " * " : " "; - System.out.println(BLUE + " " + (i + 1) + "." + RESET + " " + prefix + locations.get(i).getName()); - } - - int choice; + private static Location moveToLocation(Scanner scanner, Location current, Player player) { + int choice = -1; do { + System.out.println("Choose a location to move to:"); + for (int i = 0; i < locations.size(); i++) { + String prefix = locations.get(i).equals(current) ? " * " : " "; + System.out.println(BLUE + " " + (i + 1) + "." + RESET + " " + prefix + locations.get(i).getName()); + } choice = scanner.nextInt() - 1; + if (choice == 3 && !player.hasAllKeys()){ + System.out.println("Locked!"); + choice = -1; + } } while (choice < 0 || choice >= locations.size()); return locations.get(choice);