worked on locked doors
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
Room name: Circle Room
|
||||
Room Description: You are in the circular room. The windows to the west are bolted shut and curtains cover them.<br>To the east, a hallway. A scroll hangs on the north wall. Writing is visible.
|
||||
Locked: false
|
||||
Items:Lockpick
|
||||
Exit Rooms: W-Apple Hallway
|
||||
Room name: Apple Hallway
|
||||
Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the Circle Room and north is the Porcupine Stairs. The door to the stairs is locked. There is no key to the door.
|
||||
Locked: true
|
||||
Items:
|
||||
Exit Rooms: E-Circle Room, N-Porcupine Stairs (3rd Floor)
|
||||
Room name: Porcupine Stairs (3rd Floor)
|
||||
|
||||
@@ -54,6 +54,9 @@ class Game {
|
||||
// Read the Description
|
||||
String roomDescription = roomScanner.nextLine();
|
||||
room.setDescription(roomDescription.split(":")[1].replaceAll("<br>", "\n").trim());
|
||||
// Read the Description
|
||||
boolean locked = Boolean.parseBoolean(roomScanner.nextLine());
|
||||
room.setLocked(locked);
|
||||
// Read the Items
|
||||
String items = roomScanner.nextLine();
|
||||
try {
|
||||
@@ -232,7 +235,20 @@ class Game {
|
||||
System.out.println("You are empty handed.");
|
||||
}
|
||||
break;
|
||||
|
||||
case "open":
|
||||
boolean hasLockpick = false;
|
||||
for(int i =0; i<player.getInventory().size(); i++) {
|
||||
if(player.getInventory().get(i).equals(new Lockpick())) {
|
||||
hasLockpick = true;
|
||||
player.removeFromInventory(new Lockpick());
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(command.hasDirection()) {
|
||||
Room nextRoom = currentRoom.nextRoom(command.getDirection());
|
||||
nextRoom.setLocked(false);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
@@ -267,6 +283,9 @@ class Game {
|
||||
Room nextRoom = currentRoom.nextRoom(direction);
|
||||
if (nextRoom == null)
|
||||
System.out.println("There is no door!");
|
||||
else if(nextRoom.getLocked()) {
|
||||
System.out.println("The door is locked!");
|
||||
}
|
||||
else {
|
||||
currentRoom = nextRoom;
|
||||
System.out.println(currentRoom.longDescription());
|
||||
|
||||
@@ -26,6 +26,7 @@ class Room {
|
||||
private String description;
|
||||
private HashMap<String, Room> exits; // stores exits of this room.
|
||||
private ArrayList<Item> items;
|
||||
private boolean locked;
|
||||
|
||||
/**
|
||||
* Create a room described "description". Initially, it has no exits.
|
||||
@@ -45,6 +46,14 @@ class Room {
|
||||
items = new ArrayList<Item>();
|
||||
}
|
||||
|
||||
public void setLocked(boolean b) {
|
||||
locked = b;
|
||||
}
|
||||
|
||||
public boolean getLocked() {
|
||||
return locked;
|
||||
}
|
||||
|
||||
public void setExit(char direction, Room r) throws Exception {
|
||||
String dir = "";
|
||||
switch (direction) {
|
||||
|
||||
Reference in New Issue
Block a user