Merge remote-tracking branch 'origin/master'

This commit is contained in:
vleevalerio
2019-05-20 18:18:46 -04:00
7 changed files with 83 additions and 29 deletions

View File

@@ -1,6 +1,6 @@
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.
Items: Scroll 1,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.

View File

@@ -29,3 +29,7 @@ robes, item
water bottle, item water bottle, item
pen, item pen, item
book, item book, item
socks, item
painting, item
inventory, verb
i, verb

View File

@@ -14,21 +14,11 @@ public class Player extends Entity{
super(); super();
} }
public boolean addToInventory(String item){ public boolean addToInventory(Item item){
Class<?> clazz; if(currentInventoryWeight + item.getWeight() < INVENTORY_CAPACITY){
Item object; inventory.add(item);
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; return true;
} }
} catch (Exception e) {
return false;
}
return false; return false;
} }
@@ -37,4 +27,8 @@ public class Player extends Entity{
} }
public ArrayList<Item> getInventory() {
return inventory;
}
} }

View File

@@ -175,12 +175,24 @@ class Game {
break; break;
case "take": case "take":
if(command.hasItem()) { if(command.hasItem()) {
if(player.addToInventory(command.getItem())) { 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"); System.out.println("Taken");
}else { }else {
System.out.println("You cannot carry any more!"); System.out.println("You cannot carry any more!");
} }
} catch(Exception e) {
}
}else { }else {
System.out.println("Take what?"); System.out.println("Take what?");
} }
@@ -188,18 +200,39 @@ class Game {
break; break;
case "look": case "look":
System.out.print("Items: "); boolean hasItems = false;
String items = "";
for(Item i : currentRoom.getItems()) { for(Item i : currentRoom.getItems()) {
System.out.print(i.getName() + " "); hasItems = true;
items += i.getName() + " ";
} }
if(hasItems) {
System.out.println(currentRoom.longDescription());
System.out.print("Items: ");
System.out.print(items);
System.out.println(); System.out.println();
/* }else {
for (Item i : itemsInRooms.keySet()) { System.out.println(currentRoom.longDescription());
System.out.print(i.getName() + " "); System.out.println("There are no items.");
} }
System.out.println();
*/
break; 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: default:
return false; return false;
} }

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -187,4 +187,12 @@ class Room {
public void setDescription(String description) { public void setDescription(String description) {
this.description = description; this.description = description;
} }
public boolean hasItem(Item item) {
boolean hasItem = false;
for(Item i : items) {
if(i.equals(item))
hasItem = true;
}
return hasItem;
}
} }