finished crafting
This commit is contained in:
@@ -51,4 +51,6 @@ cream, shavingcream
|
||||
water, waterbottle
|
||||
bottle, waterbottle
|
||||
warm, warmbread
|
||||
bread, warmbread
|
||||
bread, warmbread
|
||||
battering, batteringram
|
||||
ram, batteringram
|
||||
@@ -62,4 +62,6 @@ henrypellatt, enemy
|
||||
riddler, friend
|
||||
clock, item
|
||||
keyboard, item
|
||||
lightbulb, item
|
||||
lightbulb, item
|
||||
craft, verb
|
||||
batteringram, item
|
||||
@@ -540,6 +540,51 @@ class Game {
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "craft":
|
||||
if(command.hasItem()) {
|
||||
Class<?> clazz;
|
||||
CraftableItem 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 = (CraftableItem) ctor.newInstance();
|
||||
if(object.isCraftable()) {
|
||||
boolean playerHasItems = true;
|
||||
boolean hasItem = false;
|
||||
for(Item i : object.getMaterials()) {
|
||||
hasItem = false;
|
||||
for(Item pi : player.getInventory()) {
|
||||
if(i.equals(pi)) {
|
||||
hasItem = true;
|
||||
}
|
||||
}
|
||||
if(playerHasItems) {
|
||||
playerHasItems = hasItem;
|
||||
}
|
||||
}
|
||||
if(playerHasItems) {
|
||||
if(player.addToInventory(object)) {
|
||||
for(Item i : object.getMaterials()) {
|
||||
player.removeFromInventory(i);
|
||||
}
|
||||
System.out.println("You have crafted a " + object.getName());
|
||||
}else {
|
||||
System.out.println("You cannot carry any more!");
|
||||
}
|
||||
}else {
|
||||
System.out.println("You do not have the nessecary parts to make a " + object.getName() + "!");
|
||||
}
|
||||
|
||||
}else {
|
||||
System.out.println("You cannot make that item!");
|
||||
}
|
||||
}catch(Exception e) {
|
||||
System.out.println("You cannot make that item!");
|
||||
}
|
||||
}else {
|
||||
System.out.println("Craft what?");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
10
src/com/bayviewglen/zork/Items/Batteringram.java
Normal file
10
src/com/bayviewglen/zork/Items/Batteringram.java
Normal file
@@ -0,0 +1,10 @@
|
||||
package com.bayviewglen.zork.Items;
|
||||
|
||||
public class Batteringram extends CraftableItem{
|
||||
public Batteringram() {
|
||||
super(99, "Battering Ram", "Description", false, 1, 1);
|
||||
super.addMaterial(new Base());
|
||||
super.addMaterial(new Cylinder());
|
||||
super.addMaterial(new Point());
|
||||
}
|
||||
}
|
||||
20
src/com/bayviewglen/zork/Items/CraftableItem.java
Normal file
20
src/com/bayviewglen/zork/Items/CraftableItem.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package com.bayviewglen.zork.Items;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class CraftableItem extends Item{
|
||||
private ArrayList<Item> materials;
|
||||
public CraftableItem(int id, String name, String description, boolean isConsumable, int health, int weight) {
|
||||
super(id, name, description, isConsumable, health, weight);
|
||||
materials = new ArrayList<Item>();
|
||||
}
|
||||
public boolean isCraftable() {
|
||||
return true;
|
||||
}
|
||||
public void addMaterial(Item item) {
|
||||
materials.add(item);
|
||||
}
|
||||
public ArrayList<Item> getMaterials(){
|
||||
return materials;
|
||||
}
|
||||
}
|
||||
@@ -67,5 +67,7 @@ public class Item {
|
||||
public int getDamage() {
|
||||
return this.damage;
|
||||
}
|
||||
|
||||
public boolean isCraftable() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user