battering ram break boards

This commit is contained in:
jslightham
2019-05-31 21:49:04 -04:00
parent 762ba0f04e
commit 2d16686a06

View File

@@ -314,20 +314,29 @@ class Game {
System.out.println("What do you want to open the door with?"); System.out.println("What do you want to open the door with?");
} }
boolean hasCrowbar = false; boolean hasCrowbar = false;
boolean hasBatteringRam = 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 Crowbar())) { if (player.getInventory().get(i).equals(new Crowbar())) {
hasCrowbar = true; hasCrowbar = true;
break; break;
} }
if (player.getInventory().get(i).equals(new Batteringram())) {
hasBatteringRam = true;
break;
} }
if (command.hasDirection() && hasCrowbar) { }
if (command.hasDirection() && (hasCrowbar || hasBatteringRam)) {
Room nextRoom = currentRoom.nextRoom(command.getDirection()); Room nextRoom = currentRoom.nextRoom(command.getDirection());
try { try {
if (nextRoom.getBoarded()) { if (nextRoom.getBoarded()) {
nextRoom.setBoarded(false); nextRoom.setBoarded(false);
if(hasCrowbar) {
player.removeFromInventory(new Crowbar()); player.removeFromInventory(new Crowbar());
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."); }
if(hasBatteringRam) {
System.out.println("With the battering ram, you smash through the boards on the door!");
}
} else { } else {
System.out.println("That door is already unboarded!"); System.out.println("That door is already unboarded!");
} }