+ (fix) : fixed bugs related to changing location.

This commit is contained in:
2026-05-11 12:36:46 +03:30
parent 70f03438fa
commit 82027ac95e
@@ -121,7 +121,7 @@ public class Main {
} }
break; break;
case 2: case 2:
currentLocation = moveToLocation(scanner, currentLocation); currentLocation = moveToLocation(scanner, currentLocation, player);
if (!currentLocation.hasEnemy()) { if (!currentLocation.hasEnemy()) {
spawnRandomEnemy(currentLocation, random); spawnRandomEnemy(currentLocation, random);
} }
@@ -190,16 +190,19 @@ public class Main {
} }
} }
private static Location moveToLocation(Scanner scanner, Location current) { private static Location moveToLocation(Scanner scanner, Location current, Player player) {
int choice = -1;
do {
System.out.println("Choose a location to move to:"); System.out.println("Choose a location to move to:");
for (int i = 0; i < locations.size(); i++) { for (int i = 0; i < locations.size(); i++) {
String prefix = locations.get(i).equals(current) ? " * " : " "; String prefix = locations.get(i).equals(current) ? " * " : " ";
System.out.println(BLUE + " " + (i + 1) + "." + RESET + " " + prefix + locations.get(i).getName()); System.out.println(BLUE + " " + (i + 1) + "." + RESET + " " + prefix + locations.get(i).getName());
} }
int choice;
do {
choice = scanner.nextInt() - 1; choice = scanner.nextInt() - 1;
if (choice == 3 && !player.hasAllKeys()){
System.out.println("Locked!");
choice = -1;
}
} while (choice < 0 || choice >= locations.size()); } while (choice < 0 || choice >= locations.size());
return locations.get(choice); return locations.get(choice);