diff --git a/data/rooms.dat b/data/rooms.dat
index 9bd2f96..3b09cd9 100644
--- a/data/rooms.dat
+++ b/data/rooms.dat
@@ -1,6 +1,6 @@
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. A scroll hangs on the north wall. Writing is visible.
-Items: Scroll 1,Lockpick
+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.
diff --git a/data/words.dat b/data/words.dat
index aeaf139..7a4ef89 100644
--- a/data/words.dat
+++ b/data/words.dat
@@ -28,4 +28,8 @@ garlic, item
robes, item
water bottle, item
pen, item
-book, item
\ No newline at end of file
+book, item
+socks, item
+painting, item
+inventory, verb
+i, verb
\ No newline at end of file
diff --git a/src/com/bayviewglen/zork/Entities/Player.java b/src/com/bayviewglen/zork/Entities/Player.java
index 45d42b4..695dac2 100644
--- a/src/com/bayviewglen/zork/Entities/Player.java
+++ b/src/com/bayviewglen/zork/Entities/Player.java
@@ -14,20 +14,10 @@ public class Player extends Entity{
super();
}
- public boolean addToInventory(String item){
- Class> clazz;
- Item object;
- try {
- 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;
+ public boolean addToInventory(Item item){
+ if(currentInventoryWeight + item.getWeight() < INVENTORY_CAPACITY){
+ inventory.add(item);
+ return true;
}
return false;
}
@@ -36,5 +26,9 @@ public class Player extends Entity{
inventory.remove(item);
}
+
+ public ArrayList- getInventory() {
+ return inventory;
+ }
}
diff --git a/src/com/bayviewglen/zork/Game.java b/src/com/bayviewglen/zork/Game.java
index 7bff7cc..283a47f 100644
--- a/src/com/bayviewglen/zork/Game.java
+++ b/src/com/bayviewglen/zork/Game.java
@@ -175,12 +175,24 @@ class Game {
break;
case "take":
if(command.hasItem()) {
- if(player.addToInventory(command.getItem())) {
- System.out.println("Taken");
- }else {
- System.out.println("You cannot carry any more!");
+ Class> clazz;
+ Item object;
+ try {
+ clazz = Class.forName("com.bayviewglen.zork.Items." + command.getItem().substring(0, 1).toUpperCase().trim() + command.getItem().substring(1).trim());
+ Constructor> ctor = clazz.getConstructor();
+ object = (Item) ctor.newInstance();
+ if(!currentRoom.hasItem(object)) {
+ System.out.println("This room has no " + command.getItem() + "!");
+ }
+ else if(player.addToInventory(object)) {
+ currentRoom.removeItem(object);
+ System.out.println("Taken");
+ }else {
+ System.out.println("You cannot carry any more!");
+ }
+ } catch(Exception e) {
+
}
-
}else {
System.out.println("Take what?");
}
@@ -188,18 +200,39 @@ class Game {
break;
case "look":
- System.out.print("Items: ");
+ boolean hasItems = false;
+ String items = "";
for(Item i : currentRoom.getItems()) {
- System.out.print(i.getName() + " ");
+ hasItems = true;
+ items += i.getName() + " ";
}
- System.out.println();
- /*
- for (Item i : itemsInRooms.keySet()) {
- System.out.print(i.getName() + " ");
+ if(hasItems) {
+ System.out.println(currentRoom.longDescription());
+ System.out.print("Items: ");
+ System.out.print(items);
+ System.out.println();
+ }else {
+ System.out.println(currentRoom.longDescription());
+ System.out.println("There are no items.");
}
- System.out.println();
- */
break;
+
+ case "inventory": case "i":
+ boolean hasPlayerItems = false;
+ String itemsP = "";
+ for(Item i : player.getInventory()) {
+ hasPlayerItems = true;
+ itemsP += i.getName() + " ";
+ }
+ if(hasPlayerItems) {
+ System.out.print("Inventory: ");
+ System.out.print(itemsP);
+ System.out.println();
+ }else {
+ System.out.println("You are empty handed.");
+ }
+ break;
+
default:
return false;
}
diff --git a/src/com/bayviewglen/zork/Items/Painting.java b/src/com/bayviewglen/zork/Items/Painting.java
new file mode 100644
index 0000000..8e00040
--- /dev/null
+++ b/src/com/bayviewglen/zork/Items/Painting.java
@@ -0,0 +1,7 @@
+package com.bayviewglen.zork.Items;
+public class Painting extends Item{
+
+ public Painting(){
+ super(14, "Painting", "An antique painting made from vibrant colours with an artists signature in the bottom right corner", false, 50, 1);
+ }
+}
\ No newline at end of file
diff --git a/src/com/bayviewglen/zork/Items/Socks.java b/src/com/bayviewglen/zork/Items/Socks.java
new file mode 100644
index 0000000..a5195f1
--- /dev/null
+++ b/src/com/bayviewglen/zork/Items/Socks.java
@@ -0,0 +1,8 @@
+package com.bayviewglen.zork.Items;
+public class Socks extends Item{
+
+ public Socks(){
+ super(13, "Socks", "Old socks with a lot of wear and tear, worn by Henry Pellatt", false, 5, 1);
+ }
+
+}
diff --git a/src/com/bayviewglen/zork/Room.java b/src/com/bayviewglen/zork/Room.java
index e13ad9b..bb52d8e 100644
--- a/src/com/bayviewglen/zork/Room.java
+++ b/src/com/bayviewglen/zork/Room.java
@@ -187,4 +187,12 @@ class Room {
public void setDescription(String description) {
this.description = description;
}
+ public boolean hasItem(Item item) {
+ boolean hasItem = false;
+ for(Item i : items) {
+ if(i.equals(item))
+ hasItem = true;
+ }
+ return hasItem;
+ }
}