worked on locked doors

This commit is contained in:
jslightham
2019-05-22 14:44:22 -04:00
parent ad302760eb
commit 59f51231c8
3 changed files with 56 additions and 26 deletions

View File

@@ -1,9 +1,11 @@
Room name: Circle Room 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. 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 Items:Lockpick
Exit Rooms: W-Apple Hallway Exit Rooms: W-Apple Hallway
Room name: 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. 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: Items:
Exit Rooms: E-Circle Room, N-Porcupine Stairs (3rd Floor) Exit Rooms: E-Circle Room, N-Porcupine Stairs (3rd Floor)
Room name: Porcupine Stairs (3rd Floor) Room name: Porcupine Stairs (3rd Floor)

View File

@@ -54,6 +54,9 @@ class Game {
// Read the Description // Read the Description
String roomDescription = roomScanner.nextLine(); String roomDescription = roomScanner.nextLine();
room.setDescription(roomDescription.split(":")[1].replaceAll("<br>", "\n").trim()); room.setDescription(roomDescription.split(":")[1].replaceAll("<br>", "\n").trim());
// Read the Description
boolean locked = Boolean.parseBoolean(roomScanner.nextLine());
room.setLocked(locked);
// Read the Items // Read the Items
String items = roomScanner.nextLine(); String items = roomScanner.nextLine();
try { try {
@@ -232,7 +235,20 @@ class Game {
System.out.println("You are empty handed."); System.out.println("You are empty handed.");
} }
break; 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: default:
return false; return false;
} }
@@ -267,6 +283,9 @@ class Game {
Room nextRoom = currentRoom.nextRoom(direction); Room nextRoom = currentRoom.nextRoom(direction);
if (nextRoom == null) if (nextRoom == null)
System.out.println("There is no door!"); System.out.println("There is no door!");
else if(nextRoom.getLocked()) {
System.out.println("The door is locked!");
}
else { else {
currentRoom = nextRoom; currentRoom = nextRoom;
System.out.println(currentRoom.longDescription()); System.out.println(currentRoom.longDescription());

View File

@@ -26,6 +26,7 @@ class Room {
private String description; private String description;
private HashMap<String, Room> exits; // stores exits of this room. private HashMap<String, Room> exits; // stores exits of this room.
private ArrayList<Item> items; private ArrayList<Item> items;
private boolean locked;
/** /**
* Create a room described "description". Initially, it has no exits. * Create a room described "description". Initially, it has no exits.
@@ -45,6 +46,14 @@ class Room {
items = new ArrayList<Item>(); 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 { public void setExit(char direction, Room r) throws Exception {
String dir = ""; String dir = "";
switch (direction) { switch (direction) {