eat, drop commands
This commit is contained in:
@@ -55,4 +55,5 @@ bucket, item
|
|||||||
towels, item
|
towels, item
|
||||||
open, verb
|
open, verb
|
||||||
i, verb
|
i, verb
|
||||||
unlock, verb
|
unlock, verb
|
||||||
|
drop, verb
|
||||||
@@ -1,6 +1,15 @@
|
|||||||
package com.bayviewglen.zork.Entities;
|
package com.bayviewglen.zork.Entities;
|
||||||
|
|
||||||
public class Entity {
|
public class Entity {
|
||||||
private int hunger;
|
protected double hunger;
|
||||||
private int health;
|
protected double health;
|
||||||
|
|
||||||
|
public Entity(double health, double hunger) {
|
||||||
|
this.health = health;
|
||||||
|
this.hunger = hunger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getHealth() {
|
||||||
|
return this.health;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ public class Player extends Entity{
|
|||||||
private int currentInventoryWeight;
|
private int currentInventoryWeight;
|
||||||
|
|
||||||
public Player() {
|
public Player() {
|
||||||
super();
|
super(100.0, 100.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean addToInventory(Item item){
|
public boolean addToInventory(Item item){
|
||||||
@@ -36,5 +36,17 @@ public class Player extends Entity{
|
|||||||
public ArrayList<Item> getInventory() {
|
public ArrayList<Item> getInventory() {
|
||||||
return inventory;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ class Game {
|
|||||||
System.out.println("Welcome to ESCAPE CASA LOMA!\n-----");
|
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("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.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()){
|
}else if(!command.hasDirection()){
|
||||||
System.out.println("You must specify a direction!");
|
System.out.println("You must specify a direction!");
|
||||||
}else {
|
}else {
|
||||||
System.out.println("You need a lockpick!");
|
System.out.println("What do you want to open the door with?");
|
||||||
}
|
}
|
||||||
break;
|
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":
|
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...");
|
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;
|
return true;
|
||||||
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?");
|
||||||
|
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<player.getInventory().size(); i++) {
|
||||||
|
if(object.equals(player.getInventory().get(i))) {
|
||||||
|
hasItem = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(object.isConsumable() && hasItem) {
|
||||||
|
System.out.println("Yum!");
|
||||||
|
System.out.println("Your health is now " + player.getHealth() + "%");
|
||||||
|
player.eat();
|
||||||
|
player.removeFromInventory(object);
|
||||||
|
}else if(object.isConsumable()) {
|
||||||
|
System.out.println("You do not have a " + command.getItem());
|
||||||
|
}else {
|
||||||
|
System.out.println("You cannot eat a " + command.getItem());
|
||||||
|
}
|
||||||
|
} catch(Exception e) {
|
||||||
|
System.out.println("You cannot eat a " + command.getItem());
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
System.out.println("Eat what?");
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case "take":
|
case "take":
|
||||||
if(command.hasItem()) {
|
if(command.hasItem()) {
|
||||||
@@ -268,6 +297,34 @@ class Game {
|
|||||||
System.out.println("You have nothing on you. Try and find some items.");
|
System.out.println("You have nothing on you. Try and find some items.");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case "drop":
|
||||||
|
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 has = false;
|
||||||
|
for(int i =0; i<player.getInventory().size(); i++) {
|
||||||
|
if(player.getInventory().get(i).equals(object)) {
|
||||||
|
has = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(has) {
|
||||||
|
player.removeFromInventory(object);
|
||||||
|
currentRoom.addItem(object);
|
||||||
|
System.out.println("You dropped your " + object.getName());
|
||||||
|
}else {
|
||||||
|
System.out.println("You do not have a " + object.getName());
|
||||||
|
}
|
||||||
|
} catch(Exception e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
System.out.println("Drop what?");
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user