fixed rooms, worked on take command

This commit is contained in:
jslightham
2019-05-10 12:54:16 -04:00
parent 37a428fa93
commit 9b1cd284ee
5 changed files with 90 additions and 60 deletions

View File

@@ -1,173 +1,169 @@
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. To the east, a hallway. Room Description: You are in the circular room. The windows to the west are bolted shut and curtains cover them. To the east, a hallway.
Exit Rooms: w-Apple Hallway Items:Candlestick,Candlestick
Items: Candlestick, Candlestick 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 round room and north is the stairs. You cannot see what they lead to. Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to.
Exit Rooms: e-Circle Room, n-Porcupine Stairs Items:
Items: Exit Rooms: E-Circle Room, N-Porcupine Stairs
Room Name: Porcupine Stairs Room Name: Porcupine Stairs
Room Description: You are in the Porcupine Stairs. The stone, cold walls are trapped in darkness. Below you is the second floor and above you is the third floor. Room Description: You are in the Porcupine Stairs. The stone, cold walls are trapped in darkness. Below you is the second floor and above you is the third floor.
Exit Rooms: up-Third floor, down-Second floor Items:
Items: Exit Rooms: U-Third floor, D-Second floor
Room Name: Second Floor Room Name: Second Floor
Room Description: You are now on the second floor. The hallways are empty, but some doors are slightly ajar. Room Description: You are now on the second floor. The hallways are empty, but some doors are slightly ajar.
Exit Rooms: n-Porcupine Stairs, s-Sir Harry Mill Pallat's Bedroom, w-Bulb Room, e-Pipe Room Items:
Exit Rooms: N-Porcupine Stairs, S-Sir Harry Mill Pallat's Bedroom, W-Bulb Room, E-Pipe Room
Room Name: Bulb Room Room Name: Bulb Room
Room Description: You are in the Bulb Room. There is a ragged red rug with a noticeable lump in the middle. One window facing north is bolted shut. Room Description: You are in the Bulb Room. There is a ragged red rug with a noticeable lump in the middle. One window facing north is bolted shut.
Exit Rooms: s-linen closet, e-Second Floor, w-Lady Pellat's Bedroom Items:Garlic
Items: Garlic Exit Rooms: S-linen closet, E-Second Floor, W-Lady Pellat's Bedroom
Room Name: Lady Pellat's Bedroom Room Name: Lady Pellat's Bedroom
Room Description: You are now in Lady Pellat's Bedroom. A four-post bed with elegant pink bedsheets lies in the middle of the room. A golden wardrobe sits along the east wall with a few robes hanging out. Room Description: You are now in Lady Pellat's Bedroom. A four-post bed with elegant pink bedsheets lies in the middle of the room. A golden wardrobe sits along the east wall with a few robes hanging out.
Exit Rooms: n-Sitting Area, s-Guest Bedroom, e-Bulb Room
Items: Robes Items: Robes
Exit Rooms: N-Sitting Area, S-Guest Bedroom, E-Bulb Room
Room Name: Hallway 3 Room Name: Hallway 3
Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to. Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to.
Items:
Exit Rooms: W-Round Room (third floor), N-Stairs to second floor Exit Rooms: W-Round Room (third floor), N-Stairs to second floor
Room Name: Hallway 3 Room Name: Hallway 3
Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to. Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to.
Items:
Exit Rooms: W-Round Room (third floor), N-Stairs to second floor Exit Rooms: W-Round Room (third floor), N-Stairs to second floor
Room Name: Hallway 3 Room Name: Hallway 3
Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to. Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to.
Items:
Exit Rooms: W-Round Room (third floor), N-Stairs to second floor Exit Rooms: W-Round Room (third floor), N-Stairs to second floor
Room Name: Hallway 3 Room Name: Hallway 3
Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to. Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to.
Items:
Exit Rooms: W-Round Room (third floor), N-Stairs to second floor Exit Rooms: W-Round Room (third floor), N-Stairs to second floor
Room Name: Hallway 3 Room Name: Hallway 3
Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to. Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to.
Items:
Exit Rooms: W-Round Room (third floor), N-Stairs to second floor Exit Rooms: W-Round Room (third floor), N-Stairs to second floor
Room Name: Hallway 3 Room Name: Hallway 3
Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to. Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to.
Items:
Exit Rooms: W-Round Room (third floor), N-Stairs to second floor Exit Rooms: W-Round Room (third floor), N-Stairs to second floor
Room Name: Hallway 3 Room Name: Hallway 3
Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to. Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to.
Items:
Exit Rooms: W-Round Room (third floor), N-Stairs to second floor Exit Rooms: W-Round Room (third floor), N-Stairs to second floor
Room Name: Hallway 3 Room Name: Hallway 3
Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to. Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to.
Items:
Exit Rooms: W-Round Room (third floor), N-Stairs to second floor Exit Rooms: W-Round Room (third floor), N-Stairs to second floor
Room Name: Hallway 3 Room Name: Hallway 3
Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to. Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to.
Items:
Exit Rooms: W-Round Room (third floor), N-Stairs to second floor Exit Rooms: W-Round Room (third floor), N-Stairs to second floor
Room Name: Hallway 3 Room Name: Hallway 3
Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to. Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to.
Items:
Exit Rooms: W-Round Room (third floor), N-Stairs to second floor Exit Rooms: W-Round Room (third floor), N-Stairs to second floor
Room Name: Hallway 3 Room Name: Hallway 3
Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to. Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to.
Items:
Exit Rooms: W-Round Room (third floor), N-Stairs to second floor Exit Rooms: W-Round Room (third floor), N-Stairs to second floor
Room Name: Hallway 3 Room Name: Hallway 3
Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to. Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to.
Items:
Exit Rooms: W-Round Room (third floor), N-Stairs to second floor Exit Rooms: W-Round Room (third floor), N-Stairs to second floor
Room Name: Hallway 3 Room Name: Hallway 3
Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to. Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to.
Items:
Exit Rooms: W-Round Room (third floor), N-Stairs to second floor Exit Rooms: W-Round Room (third floor), N-Stairs to second floor
Room Name: Hallway 3 Room Name: Hallway 3
Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to. Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to.
Items:
Exit Rooms: W-Round Room (third floor), N-Stairs to second floor Exit Rooms: W-Round Room (third floor), N-Stairs to second floor
Room Name: Hallway 3 Room Name: Hallway 3
Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to. Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to.
Items:
Exit Rooms: W-Round Room (third floor), N-Stairs to second floor Exit Rooms: W-Round Room (third floor), N-Stairs to second floor
Room Name: Round Room (third floor) Room Name: Round Room (third floor)
Room Description: You are in the round room. The windows to the west are bolted shut and curtains cover them. To the east, a hallway. Room Description: You are in the round room. The windows to the west are bolted shut and curtains cover them. To the east, a hallway.
Items:
Exit Rooms: E-Hallway 3 Exit Rooms: E-Hallway 3
Room Name: Hallway 3 Room Name: Hallway 3
Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to. Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to.
Items:
Exit Rooms: W-Round Room (third floor), N-Stairs to second floor Exit Rooms: W-Round Room (third floor), N-Stairs to second floor
Room Name: Hallway 3 Room Name: Hallway 3
Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to. Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to.
Items:
Exit Rooms: W-Round Room (third floor), N-Stairs to second floor Exit Rooms: W-Round Room (third floor), N-Stairs to second floor
Room Name: Hallway 3 Room Name: Hallway 3
Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to. Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to.
Items:
Exit Rooms: W-Round Room (third floor), N-Stairs to second floor Exit Rooms: W-Round Room (third floor), N-Stairs to second floor
Room Name: Hallway 3 Room Name: Hallway 3
Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to. Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to.
Items:
Exit Rooms: W-Round Room (third floor), N-Stairs to second floor Exit Rooms: W-Round Room (third floor), N-Stairs to second floor
Room Name: Hallway 3 Room Name: Hallway 3
Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to. Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to.
Items:
Exit Rooms: W-Round Room (third floor), N-Stairs to second floor Exit Rooms: W-Round Room (third floor), N-Stairs to second floor
Room Name: Hallway 3 Room Name: Hallway 3
Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to. Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to.
Items:
Exit Rooms: W-Round Room (third floor), N-Stairs to second floor Exit Rooms: W-Round Room (third floor), N-Stairs to second floor
Room Name: Hallway 3 Room Name: Hallway 3
Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to. Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to.
Items:
Exit Rooms: W-Round Room (third floor), N-Stairs to second floor Exit Rooms: W-Round Room (third floor), N-Stairs to second floor
Room Name: Hallway 3 Room Name: Hallway 3
Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to. Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to.
Items:
Exit Rooms: W-Round Room (third floor), N-Stairs to second floor Exit Rooms: W-Round Room (third floor), N-Stairs to second floor
Room Name: Hallway 3 Room Name: Hallway 3
Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to. Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to.
Items:
Exit Rooms: W-Round Room (third floor), N-Stairs to second floor Exit Rooms: W-Round Room (third floor), N-Stairs to second floor
Room Name: Hallway 3 Room Name: Hallway 3
Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to. Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to.
Items:
Exit Rooms: W-Round Room (third floor), N-Stairs to second floor Exit Rooms: W-Round Room (third floor), N-Stairs to second floor
Room Name: Hallway 3 Room Name: Hallway 3
Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to. Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to.
Items:
Exit Rooms: W-Round Room (third floor), N-Stairs to second floor Exit Rooms: W-Round Room (third floor), N-Stairs to second floor
Room Name: Hallway 3 Room Name: Hallway 3
Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to. Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to.
Items:
Exit Rooms: W-Round Room (third floor), N-Stairs to second floor Exit Rooms: W-Round Room (third floor), N-Stairs to second floor
Room Name: Hallway 3 Room Name: Hallway 3
Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to. Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to.
Items:
Exit Rooms: W-Round Room (third floor), N-Stairs to second floor Exit Rooms: W-Round Room (third floor), N-Stairs to second floor
Room Name: Hallway 3 Room Name: Hallway 3
Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to. Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to.
Items:
Exit Rooms: W-Round Room (third floor), N-Stairs to second floor Exit Rooms: W-Round Room (third floor), N-Stairs to second floor
Room Name: Hallway 3 Room Name: Hallway 3
Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to. Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to.
Items:
Exit Rooms: W-Round Room (third floor), N-Stairs to second floor Exit Rooms: W-Round Room (third floor), N-Stairs to second floor
Room Name: Hallway 3 Room Name: Hallway 3
Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to. Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to.
Items:
Exit Rooms: W-Round Room (third floor), N-Stairs to second floor Exit Rooms: W-Round Room (third floor), N-Stairs to second floor
Room Name: Hallway 3 Room Name: Hallway 3
Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to. Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to.
Items:
Exit Rooms: W-Round Room (third floor), N-Stairs to second floor Exit Rooms: W-Round Room (third floor), N-Stairs to second floor
Room Name: Hallway 3 Room Name: Hallway 3
Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to. Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to.
Items:
Exit Rooms: W-Round Room (third floor), N-Stairs to second floor Exit Rooms: W-Round Room (third floor), N-Stairs to second floor
Room Name: Hallway 3 Room Name: Hallway 3
Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to. Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to.
Items:
Exit Rooms: W-Round Room (third floor), N-Stairs to second floor Exit Rooms: W-Round Room (third floor), N-Stairs to second floor
Room Name: Hallway 3 Room Name: Hallway 3
Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to. Room Description: You are in an empty hallway. Many closed doors surround you. To the west is the round room and north is the stairs. You cannot see what they lead to.
Items:
Exit Rooms: W-Round Room (third floor), N-Stairs to second floor Exit Rooms: W-Round Room (third floor), N-Stairs to second floor

View File

@@ -12,6 +12,9 @@ s, direction
e, direction e, direction
up, direction up, direction
down, direction down, direction
d, direction
u, direction
eat, verb eat, verb
candlestick, item candlestick, item
look, verb look, verb
take, verb

View File

@@ -89,7 +89,7 @@ class Command {
} }
public boolean hasItem(){ public boolean hasItem(){
return item.equals(""); return !item.equals("");
} }
public boolean hasDirection() { public boolean hasDirection() {
return CommandWords.isDirection(direction); return CommandWords.isDirection(direction);
@@ -97,4 +97,7 @@ class Command {
public String getDirection() { public String getDirection() {
return direction; return direction;
} }
public String getItem() {
return item;
}
} }

View File

@@ -1,6 +1,8 @@
package com.bayviewglen.zork.Entities; package com.bayviewglen.zork.Entities;
import com.bayviewglen.zork.Items.Item; import com.bayviewglen.zork.Items.*;
import java.lang.reflect.Constructor;
import java.util.ArrayList; import java.util.ArrayList;
public class Player extends Entity{ public class Player extends Entity{
@@ -12,11 +14,20 @@ public class Player extends Entity{
super(); super();
} }
public boolean addToInventory(Item item){ public boolean addToInventory(String item){
if(currentInventoryWeight + item.getWeight() < INVENTORY_CAPACITY){ Class<?> clazz;
inventory.add(item); Item object;
System.out.println(item.getName() + " add"); try {
return true; clazz = Class.forName("com.bayviewglen.zork.Items." + item.trim());
Constructor<?> ctor = clazz.getConstructor();
object = (Item) ctor.newInstance();
if(currentInventoryWeight + object.getWeight() < INVENTORY_CAPACITY){
inventory.add(object);
return true;
}
} catch (Exception e) {
return false;
} }
return false; return false;
} }

View File

@@ -6,6 +6,7 @@ import java.lang.reflect.Constructor;
import java.util.HashMap; import java.util.HashMap;
import java.util.Scanner; import java.util.Scanner;
import com.bayviewglen.zork.Entities.Player;
import com.bayviewglen.zork.Items.*; import com.bayviewglen.zork.Items.*;
/** /**
@@ -26,6 +27,7 @@ import com.bayviewglen.zork.Items.*;
*/ */
class Game { class Game {
private Parser parser; private Parser parser;
private Player player;
private Room currentRoom; private Room currentRoom;
// This is a MASTER object that contains all of the rooms and is easily // This is a MASTER object that contains all of the rooms and is easily
// accessible. // accessible.
@@ -110,11 +112,12 @@ class Game {
public Game() { public Game() {
try { try {
initRooms("data/Rooms.dat"); initRooms("data/Rooms.dat");
currentRoom = masterRoomMap.get("ROOM_1"); currentRoom = masterRoomMap.get("CIRCLE_ROOM");
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
parser = new Parser(); parser = new Parser();
player = new Player();
} }
/** /**
@@ -171,6 +174,20 @@ class Game {
case "eat": case "eat":
System.out.println("Do you really think you should be eating at a time like this?"); System.out.println("Do you really think you should be eating at a time like this?");
break; break;
case "take":
if(command.hasItem()) {
if(player.addToInventory(command.getItem())) {
System.out.println("Taken");
}else {
System.out.println("You cannot carry any more!");
}
}else {
System.out.println("Take what?");
}
break;
case "look": case "look":
System.out.print("Items: "); System.out.print("Items: ");
for(Item i : currentRoom.getItems()) { for(Item i : currentRoom.getItems()) {