From 8f8a55949a8c358605ab6f70520f16c73a9590cc Mon Sep 17 00:00:00 2001 From: jslightham <31053827+jslightham@users.noreply.github.com> Date: Mon, 27 May 2019 00:03:23 -0400 Subject: [PATCH] eat, drop commands --- data/words.dat | 3 +- src/com/bayviewglen/zork/Entities/Entity.java | 13 +++- src/com/bayviewglen/zork/Entities/Player.java | 14 ++++- src/com/bayviewglen/zork/Game.java | 63 ++++++++++++++++++- 4 files changed, 86 insertions(+), 7 deletions(-) diff --git a/data/words.dat b/data/words.dat index 7c53303..fc4e942 100644 --- a/data/words.dat +++ b/data/words.dat @@ -55,4 +55,5 @@ bucket, item towels, item open, verb i, verb -unlock, verb \ No newline at end of file +unlock, verb +drop, verb \ No newline at end of file diff --git a/src/com/bayviewglen/zork/Entities/Entity.java b/src/com/bayviewglen/zork/Entities/Entity.java index bb2b79a..ee633c2 100644 --- a/src/com/bayviewglen/zork/Entities/Entity.java +++ b/src/com/bayviewglen/zork/Entities/Entity.java @@ -1,6 +1,15 @@ package com.bayviewglen.zork.Entities; public class Entity { - private int hunger; - private int health; + protected double hunger; + protected double health; + + public Entity(double health, double hunger) { + this.health = health; + this.hunger = hunger; + } + + public double getHealth() { + return this.health; + } } diff --git a/src/com/bayviewglen/zork/Entities/Player.java b/src/com/bayviewglen/zork/Entities/Player.java index 3f8611d..37ecde8 100644 --- a/src/com/bayviewglen/zork/Entities/Player.java +++ b/src/com/bayviewglen/zork/Entities/Player.java @@ -11,7 +11,7 @@ public class Player extends Entity{ private int currentInventoryWeight; public Player() { - super(); + super(100.0, 100.0); } public boolean addToInventory(Item item){ @@ -36,5 +36,17 @@ public class Player extends Entity{ public ArrayList getInventory() { return inventory; } + + public void eat() { + // TODO Do we want health or hunger? + health+=5; + hunger+=5; + if(health > 100.0) { + health = 100.0; + } + if(hunger > 100.0) { + hunger = 100.0; + } + } } diff --git a/src/com/bayviewglen/zork/Game.java b/src/com/bayviewglen/zork/Game.java index 4cd983a..99a0b41 100644 --- a/src/com/bayviewglen/zork/Game.java +++ b/src/com/bayviewglen/zork/Game.java @@ -153,7 +153,7 @@ class Game { System.out.println("Welcome to ESCAPE CASA LOMA!\n-----"); System.out.println("A new, fresh take on the escape-room,\nby Johnathon, Luca, Victoria and Evan "); System.out.println("Type \"play\" to play the game. If you want to close the game at any time, type \"quit\"."); - System.out.print(">"); + System.out.print("> "); } /** @@ -189,7 +189,7 @@ class Game { }else if(!command.hasDirection()){ System.out.println("You must specify a direction!"); }else { - System.out.println("You need a lockpick!"); + System.out.println("What do you want to open the door with?"); } break; case "go": case "n": case "s": case "e": case "w": case "north": case "south": case "west": case "east": case "up": case "down": case "d": case "u": @@ -207,7 +207,36 @@ class Game { System.out.println("If you insist... \n Poof! You're gone. You're out of the castle now, but now a new, grand new adventure begins..."); return true; 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?"); + if(command.hasItem()) { + 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(); + boolean hasItem = false; + for(int i=0; i 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(); + boolean has = false; + for(int i =0; i