This commit is contained in:
Luca Carnegie
2019-05-31 21:34:04 -04:00

View File

@@ -269,20 +269,31 @@ class Game {
case "open": case "open":
case "unlock": case "unlock":
boolean hasLockPick = false; boolean hasLockPick = false;
boolean hasKey = false;
for (int i = 0; i < player.getInventory().size(); i++) { for (int i = 0; i < player.getInventory().size(); i++) {
if (player.getInventory().get(i).equals(new Lockpick())) { if (player.getInventory().get(i).equals(new Lockpick())) {
hasLockPick = true; hasLockPick = true;
break; break;
} }
if (player.getInventory().get(i).equals(new Key())) {
hasKey = true;
break;
}
} }
if (command.hasDirection() && hasLockPick) { if (command.hasDirection() && (hasLockPick || hasKey)) {
Room nextRoom = currentRoom.nextRoom(command.getDirection()); Room nextRoom = currentRoom.nextRoom(command.getDirection());
try { try {
if(nextRoom.getLocked()) { if(nextRoom.getLocked()) {
nextRoom.setLocked(false); nextRoom.setLocked(false);
if(hasLockPick) {
player.removeFromInventory(new Lockpick()); player.removeFromInventory(new Lockpick());
System.out.println("After a little bit of picking, a click is heard and the door opens slightly!"); System.out.println("After a little bit of picking, a click is heard and the door opens slightly!");
}
if(hasKey) {
player.removeFromInventory(new Key());
System.out.println("With great force, you turn the key in the keyhole and the door unclocks! However, the key broke in the keyhole.");
}
if(!nextRoom.getBoarded()) if(!nextRoom.getBoarded())
break; break;
}else{ }else{
@@ -314,7 +325,7 @@ class Game {
System.out.println( System.out.println(
"With great effort, you pry the boards off the door with the crowbar! However, it breaks and is no longer useable."); "With great effort, you pry the boards off the door with the crowbar! However, it breaks and is no longer useable.");
} else { } else {
System.out.println("That door is already unlocked!"); System.out.println("That door is already unboarded!");
} }
} catch (Exception e) { } catch (Exception e) {
System.out.println("There is no door there!"); System.out.println("There is no door there!");
@@ -322,7 +333,7 @@ class Game {
} else if (!command.hasDirection()) { } else if (!command.hasDirection()) {
} else { } else {
System.out.println("What do you want to unboard the door with?");
} }
break; break;
case "go": case "go":