Question: I need to fix this code on a huge java project called collosal cave. I left out most properties files and classes for location and

I need to fix this code on a huge java project called "collosal cave". I left out most properties files and classes for location and an item, if needed I can put everything or just upload a file somewhere if would be easier but they all take same layout I have of the ones I provided. I will copy all the classes below:

CCaveElement Class:

import java.io.File;

import java.io.FileInputStream;

import java.io.IOException;

import java.io.Serializable;

import java.util.Properties;

/**

*

* Common interface for everything in the game. Items such as Food and Keys are elements.

* Rooms such as the well house are elements.

*

* This is a minimal function of a cave element. It will have an identifier, a long description

* and a short description. Many (most) elements will have other data or behaviors, but they will

* be supported by the code unique to that item or room.

*

* We exploit the Java 8 Interface enhancement of static methods that can have code supplied

* in them.

*

* We will cover the Serializable interface later in the semester. You can either remove it, or ignore it.

* Leaving it will cause Warnings, and Java want a "serial version id" static final String. Leaving the warning

* won't hurt anything. Removing it will not require an inordinate amount of pain later. Either decision is fine.

*

* @author parks

*

*/

public interface CCaveElement extends Serializable {

public static final String RESOURCE_DIR = "resources/";

public static final String LONG_DESCRIPTION = "longdescription";

public static final String SHORT_DESCRIPTION = "shortdescription";

/**

* Getter for a long description

*

* @return the long description for

*/

String getLongDescription();

/**

* Getter for a short description

*

* @return the short description for

*/

String getShortDescription();

/**

* Getter for "this" item's identifier

*

* @return the identifier for this item

*/

String getId();

/**

* Tests whether this element has the given id

*

* @param identifier

* identifier to compare to this element's id

*

* @return true if the given identifier is equal to ignoring case this element's

* id, false otherwise

*/

boolean isId(String identifier);

/**

* Utility to create the properties for a given identifier of a cave element.

*

* The properties from RESOUCE_DIR/identifier.properties file is read into a

* Properties object and returned.

*

* @param id

* identifier of a cave element.

*

* @return properties from the properties file associated with identifier. This

* Properties object will be empty if there is no such properties file.

*/

static Properties getPropertiesForId(String id) {

Properties p = new Properties();

FileInputStream fis = null;

try {

File f = new File(RESOURCE_DIR + id + ".properties");

fis = new FileInputStream(f);

p.load(fis);

} catch (IOException e) {

System.err.println("no prop file for " + id);

} finally {

if (fis != null)

try {

fis.close();

} catch (IOException e) {

}

fis = null;

}

return p;

}

}

RoomDirectory Class:

import java.util.ArrayList;

import edu.waketech.ccave.item.Bed;

import edu.waketech.ccave.item.CCaveItem;

import edu.waketech.ccave.item.Chairs;

import edu.waketech.ccave.item.Crops;

import edu.waketech.ccave.item.Dirt;

import edu.waketech.ccave.item.Door;

import edu.waketech.ccave.item.Fire;

import edu.waketech.ccave.item.Food;

import edu.waketech.ccave.item.Hoe;

import edu.waketech.ccave.item.Keys;

import edu.waketech.ccave.item.Lamp;

import edu.waketech.ccave.item.Rake;

import edu.waketech.ccave.item.River;

import edu.waketech.ccave.item.Shovel;

import edu.waketech.ccave.item.Table;

import edu.waketech.ccave.item.Trees;

import edu.waketech.ccave.item.Water;

import edu.waketech.ccave.location.Bathroom;

import edu.waketech.ccave.location.Bedroom;

import edu.waketech.ccave.location.CCaveRoom;

import edu.waketech.ccave.location.Dining;

import edu.waketech.ccave.location.EndOfRoad;

import edu.waketech.ccave.location.Garage;

import edu.waketech.ccave.location.Garden;

import edu.waketech.ccave.location.Kitchen;

import edu.waketech.ccave.location.Tunnels;

import edu.waketech.ccave.location.Washroom;

import edu.waketech.ccave.location.Wellhouse;

public class RoomDirectory {

private ArrayList caveRoom = new ArrayList<>();

private static RoomDirectory instance = new RoomDirectory();

private final CCaveRoom[] ALL_ITEMS = {

new Bathroom(),

new Bedroom(),

new CCaveRoom(),

new Dining(),

new EndOfRoad(),

new Garage(),

new Garden(),

new Kitchen(),

new Tunnels(),

new Washroom(),

new Wellhouse(),

};

private RoomDirectory() {

for (CCaveRoom cci: ALL_ITEMS) {

caveRoom.add(cci);

}

}

public static RoomDirectory getInstance() {

return instance;

}

public boolean contains(java.lang.String id) {

for (CCaveRoom ele : caveRoom) {

if (((CCaveElement) ele).getId().equalsIgnoreCase(id))

return true;

}

return false;

}

public int indexOf(java.lang.String id) {

int i = 0;

for (i = 0; i < caveRoom.size(); i++) {

if (((CCaveElement) caveRoom.get(i)).getId().equalsIgnoreCase(id))

return i;

}

return -1;

}

public boolean remove(java.lang.String id) {

int i = -1;

boolean found = false;

while (!found) {

i++;

if (((CCaveElement) caveRoom.get(i)).getId().equalsIgnoreCase(id))

found = true;

}

if (i < caveRoom.size()) {

caveRoom.remove(i);

return true;

}

return false;

}

public CCaveRoom get(java.lang.String id) {

int i = indexOf(id);

if (i == -1) return null;

return caveRoom.get(i);

}

}

ItemDirectory Class:

import java.util.ArrayList;

import edu.waketech.ccave.item.Bed;

import edu.waketech.ccave.item.CCaveItem;

import edu.waketech.ccave.item.Chairs;

import edu.waketech.ccave.item.Crops;

import edu.waketech.ccave.item.Dirt;

import edu.waketech.ccave.item.Door;

import edu.waketech.ccave.item.Fire;

import edu.waketech.ccave.item.Food;

import edu.waketech.ccave.item.Hoe;

import edu.waketech.ccave.item.Keys;

import edu.waketech.ccave.item.Lamp;

import edu.waketech.ccave.item.Rake;

import edu.waketech.ccave.item.River;

import edu.waketech.ccave.item.Shovel;

import edu.waketech.ccave.item.Table;

import edu.waketech.ccave.item.Trees;

import edu.waketech.ccave.item.Water;

/**

* Singleton that maintains the "item identifier" to "item object" mapping.

*

* Singleton classes are constructed so that there will be at most one instance

* of them. This class uses an eager implementation.

*

*

References to this object must be acquired by

*

* ItemDirectory itemDirec = ItemDirectory.getInstance();

*

* @author parks

*

*/

public class ItemDirectory {

private ArrayList caveItem = new ArrayList<>();

private static ItemDirectory instance = new ItemDirectory();

/*

* Doing something clever with Class.forName would be better,

* but we're not covering the reflection API.

*

* This isn't too, too wasteful. The duplicate

* configuration information is the worst part.

*/

private final CCaveItem[] ALL_ITEMS = {

new Food(),

new Bed(),

new Chairs(),

new Crops(),

new Dirt(),

new Door(),

new Fire(),

new Hoe(),

new Keys(),

new Lamp(),

new Rake(),

new River(),

new Shovel(),

new Table(),

new Trees(),

new Water(),

};

private ItemDirectory() {

for (CCaveItem cci: ALL_ITEMS) {

caveItem.add(cci);

}

}

/**

* Static method to provide access to this singleton's object reference.

*

* @return reference to ItemDirectory object

*/

public static ItemDirectory getInstance() {

return instance;

}

/**

* Add a new element to the Directory

*

* @param itemToAdd will be added to the Item Directory

*

* @return true if the Directory was modified as a result of the call,

* false otherwise.

*/

public boolean add(CCaveItem itemToAdd) {

return caveItem.add(itemToAdd);

}

/**

* The number of items in the directory

*

* @return the number of items currently in the directory

*/

public int size() {

return caveItem.size();

}

/**

* Accessor to retrieve a reference to the given element of the Directory.

* CCaveItem objects are numbered in the same order that they were received.

*

* @param indexToRetrieve index (0 origin) of the CCaveItem to retrieve.

*

* @return the item at the specified position in the Directory, or null if

* no such item exists.

*/

public CCaveItem get(int indexToRetrieve) {

return caveItem.get(indexToRetrieve);

}

/**

* Remove an item from the Directory.

*

* @param itemToRemove the item to remove will satisfy the equals relationship

*

* @return true if the directory was modified as a result of this method call, false otherwise.

*/

public boolean remove(CCaveItem itemToRemove) {

return caveItem.remove(itemToRemove);

}

/**

* Clear the entire directory. After this call, the Directory will contain no elements.

*/

public void clear() {

caveItem.clear();

}

/**

* Utility method in case we know the identifier we're interested in, but don't

* need an Item reference.

*

*

*

* @param id

* of the item we wish to verify is or is not in the directory,

* ignoring case

*

* @return true if an Item is in the Directory with the given id, false

* otherwise

*/

public boolean contains(String id) {

for (CCaveItem ele : caveItem) {

if (ele.getId().equalsIgnoreCase(id))

return true;

}

return false;

}

/**

* Utility method to find the location of an Item with a given identifier,

* ignoring case.

*

* @param id

* identifier whose associated Item we wish to find, ignoring case

*

* @return the location within the List of the item with the associated id, or

* -1 if no such item exists.

*/

public int indexOf(String id) {

int i = 0;

for (i = 0; i < caveItem.size(); i++) {

if (caveItem.get(i).getId().equalsIgnoreCase(id))

return i;

}

return -1;

}

/**

*

* Utility method to remove the item with a given identifier,

* ignoring case.

*

* @param id

* identifier whose associated Item we wish to remove, ignoring case

*

*

* @return true if an item was removed from the Directory, false otherwise

*/

public boolean remove(String id) {

int i = -1;

boolean found = false;

while (!found) {

i++;

if (caveItem.get(i).getId().equalsIgnoreCase(id))

found = true;

}

if (i < caveItem.size()) {

caveItem.remove(i);

return true;

}

return false;

}

/**

*

* Utility method to fetch the item with a given identifier,

* ignoring case.

*

* @param id

* identifier whose associated Item we wish to fetch, ignoring case

*

*

* @return item in the Directory with the given identifier, null if no such item exists

*/

public CCaveItem get(String id) {

int i = indexOf(id);

if (i == -1) return null;

return caveItem.get(i);

}

/**

* Return all of the items currently in a given room.

*

* @param roomId the identifier of the room whose items we wish to return

*

* @return List of items in the given room. The List will be empty if there are no such items.

*/

public ArrayList getItemsInRoom(String roomId) {

ArrayList roomItems = new ArrayList<>();

for (CCaveItem ele: caveItem) {

if (ele.getLocation().equalsIgnoreCase(roomId)) roomItems.add(ele);

}

return roomItems;

}

}

Direction Class:

import java.io.File;

import java.io.FileInputStream;

import java.io.IOException;

import java.util.ArrayList;

import java.util.Properties;

/**

* All possible directions that a player can travel.

* We read a properties file to determine the synonyms

* for each direction.

*

* This enum reads a properties file for each enum value in the resources directory, such as

*

    *

  • n.properties

    *

  • s.properties

    *

  • etc.

    *

* The keys of these properties files don't really matter--the values do. So

* for Direction.N,

* in n.properties

*

    *

  • n=north

    *

  • n1=othernorthvalue

    *

  • n2=anothernorthvalue

    *

* will all define synonym String values for Direction.N.

*

* @author parks

*

*/

public enum Direction {

N(),

S(),

E(),

W(),

NE(),

NW(),

SE(),

SW(),

UP(),

DOWN(),

UNKNOWN();

public static final String RESOURCE_DIR = "resources/";

private final ArrayList synonyms = new ArrayList<>();

/**

* enum-wide method to provide a more friendly valueOf method.

* We take a String representation of an enum value or synonym

* and, ignoring case, return the corresponding Direction enum value.

*

* This method steps through every possible enum value, which it

* can do using

*

* values().

*

* It then tests whether possibleAlt matches one of those values.

* (See isSynonym)

*

* @param possibleAlt String representing a case-insensitive, synonym-based Direction value

*

* @return the Direction value associated with possibleAlt, or Direction.UNKNOWN

*/

public static Direction findSynonym(String possibleAlt) {

for (Direction currentDir : values()) {

if (currentDir.toString().equalsIgnoreCase(possibleAlt))

return currentDir;

if (currentDir.isSynonym(possibleAlt)) return currentDir;

}

return Direction.UNKNOWN;

}

private Direction() {

Properties p = new Properties();

FileInputStream fis = null;

try {

File f = new File(RESOURCE_DIR + this.toString() + ".properties");

fis = new FileInputStream(f);

p.load(fis);

for (Object key : p.keySet()) {

String synWord = (String) key;

String directionSyn = p.getProperty(synWord);

synonyms.add(directionSyn);

}

} catch (IOException e) {

System.out.println("no nls file for " + this);

} finally {

if (fis != null)

try {

fis.close();

} catch (IOException e) {

}

fis = null;

}

}

/**

* Determine whether a given String value represents this

* Direction value ignoring case, or one of its synonyms

* ignoring case.

*

* @param possibleAlt a possible String representation of this Direction or

* one of its synonym values

*

* @return true if possibleAlt is a valid String value for this Direction or

* one of its synonyms, all ignoring case

*/

public boolean isSynonym(String possibleAlt) {

if (this.toString().equalsIgnoreCase(possibleAlt)) return true;

for (String syn: synonyms) {

if (syn.equalsIgnoreCase(possibleAlt)) return true;

}

return false;

}

/**

* Determines if isSynonym in a static context

* @param String s, is the string that requires testing of its status as a synonym

* @return boolean; true if synonym, else fails

* @author Occhipinti

*/

public static boolean isStaticSynonym(String s) {

for(Direction direction : Direction.values()) {

if(direction.synonyms.contains(s) || s.equals(direction.toString())) return true;

}

return false;

}

}

Spelunker Class:

import java.util.ArrayList;

import edu.waketech.ccave.common.CCaveElement;

import edu.waketech.ccave.common.Direction;

import edu.waketech.ccave.common.ItemDirectory;

import edu.waketech.ccave.common.RoomDirectory;

import edu.waketech.ccave.item.CCaveItem;

import edu.waketech.ccave.location.CCaveRoom;

/**

* Our fearless spelunker.

*

* We track the inventory of Items that we're carrying by assigning them the

* location SPELUNKER_ID. It's not really a "CCaveRoom," but it is a unique

* String and can let us identify the items we're carrying versus the items that

* we're not.

*

*

* If we were doing a Model-View-Controller design pattern for this game (and

* we're close, but not quite there), this would be our controller. The types

* associated with Rooms and Items would be our data model.

*

* @author parks

*

*/

public class Spelunker implements CCaveElement {

/**

*

*/

private static final long serialVersionUID = 1786845014557682582L;

public static final String SPELUNKER_ID = "spelunker";

public RoomDirectory roomDirec = RoomDirectory.getInstance();

private CCaveRoom currentLocation;

/**

* Create a spelunker with a given name and starting location.

*

* @param startRoom

* Were We Start

*/

public Spelunker(String startRoom) {

currentLocation = roomDirec.get(startRoom);

}

/**

* Assign the spelunker to the given location

*

* @param location will become the current location of the spelunker

*/

public void setLocation(CCaveRoom location) {

this.currentLocation = location;

}

/**

* Move the player from the current location in the given direction. Update our

* state as appropriate.

*

*

* @param direction

* Direction to move

*/

public void move(CCaveRoom direction) {

currentLocation = currentLocation.nextRoom(direction);

}

/**

* Take some action on an inventory item--pick it up, drop it, etc.

*

* Dropped items are assigned to be in our current location. Items that are

* picked up are assigned the location SPELUNKER_ID.

*

* @param whatToDo

* the command to perform, like GET or DROP

* @param objectOfAction

* the item to pick up or drop or do whatever with

*/

public void changeInventory(ItemCommand whatToDo, String objectOfAction) {

ItemDirectory itemDirec = ItemDirectory.getInstance();

if (whatToDo == ItemCommand.GET) {

CCaveItem itemObj = itemDirec.get(objectOfAction);

if (itemObj != null)

itemObj.setLocation(SPELUNKER_ID);

;

} else if (whatToDo == ItemCommand.DROP) {

CCaveItem itemObj = itemDirec.get(objectOfAction);

if (itemObj != null) {

itemObj.setLocation(currentLocation.getId());

}

}

}

// NOT I18N CAPABLE

@Override

public String getLongDescription() {

String cRoom = currentLocation.getLongDescription();

String roomInventory = currentLocation.getContentsLongDescription();

StringBuilder youHave = new StringBuilder();

youHave.append("you have ");

ItemDirectory direc = ItemDirectory.getInstance();

ArrayList contents = direc.getItemsInRoom(SPELUNKER_ID);

for (CCaveItem ele : contents) {

youHave.append(ele.getLongDescription());

youHave.append(" ");

}

return "You are in " + cRoom + " In here is" + roomInventory + " and you have " + youHave.toString();

}

// NOT I18N CAPABLE

@Override

public String getShortDescription() {

String cRoom = currentLocation.getShortDescription();

StringBuilder youHave = new StringBuilder();

youHave.append("you have ");

ItemDirectory direc = ItemDirectory.getInstance();

ArrayList contents = direc.getItemsInRoom(SPELUNKER_ID);

for (CCaveItem ele : contents) {

youHave.append(ele.getShortDescription());

}

return "You are in " + cRoom + " and has " + youHave;

}

@Override

public String getId() {

return SPELUNKER_ID;

}

@Override

public boolean isId(String identifier) {

return SPELUNKER_ID.equalsIgnoreCase(identifier);

}

/**

* If we get a command that's classified as "OTHER," we find the item being

* manipulated and rely on it to do whatever specific processing is necessary.

*

* @param cmd

* The command to be executed

*

* @param item

* the item being manipulated

*/

public void otherCommand(ItemCommand cmd, String item) {

// if we can identify the item, we'll operate on it and it alone

CCaveItem caveItem = ItemDirectory.getInstance().get(item);

if (caveItem != null) {

caveItem.executeCommand(cmd, item, currentLocation);

}

}

public Direction move(Direction dir) {

// TODO Auto-generated method stub

return dir;

}

}

ItemCommand Class:

import java.io.File;

import java.io.FileInputStream;

import java.io.IOException;

import java.util.HashMap;

import java.util.Map;

import java.util.Properties;

/**

* This enum lists the commands that can affect Cave items, such as FOOD or

* WATERBOTTLE

*

* @author parks

*

*/

public enum ItemCommand {

GET, DROP, EAT, DRINK, UNKNOWN;

private static final String RESOURCE_DIR = "resources/";

private static final String ITEM_COMMAND_FILE = "itemcommand";

private static Map synonyms = new HashMap<>();

/**

* This is an enum-wide friendly version of valueOf. It ignores case and also

* handles synonyms, making it NLS friendly.

*

* @param key

* String value identifying the enum value to return.

*

* @return ItemCommand value associated with the given parameter, or

* ItemCommand.UNKNOWN otherwise.

*/

public static ItemCommand findItemCommand(String key) {

if (synonyms.isEmpty()) {

readSynonyms();

}

for (ItemCommand r : ItemCommand.values()) {

if (key.equalsIgnoreCase(r.toString()))

return r;

ItemCommand ic = ItemCommand.synonyms.get(key);

if ((ic != null) && (ic != UNKNOWN))

return ic;

}

return UNKNOWN;

}

private ItemCommand() {

}

private static void readSynonyms() {

Properties p = new Properties();

FileInputStream fis = null;

try {

File f = new File(RESOURCE_DIR + ITEM_COMMAND_FILE + ".properties");

fis = new FileInputStream(f);

p.load(fis);

for (Object o : p.keySet()) {

String syn = (String) o;

String item = p.getProperty(syn);

ItemCommand trueCmd = ItemCommand.valueOf(item);

synonyms.put(syn, trueCmd);

}

} catch (IOException e) {

e.printStackTrace();

} finally {

if (fis != null)

try {

fis.close();

} catch (IOException e) { }

}

}

/**

* Returns the lower case String value of this enum value

*

* @return this ItemCommand's value as a String in lower case.

*/

public String getId() {

return this.toString().toLowerCase();

}

}

InputType Class:

/**

* All possible classes of input: movement, inventory management, looking around, and "other."

*

* The hope is that if we can sort various commands into a smaller number of

* types, then processing will be easier to handle.

*

* @author parks

*

*/

public enum InputType {

MOVE,

INVENTORY,

LOOK,

OTHER,

;

}

InputParser Class:

import java.util.Scanner;

import edu.waketech.ccave.common.Direction;

import edu.waketech.ccave.common.ItemDirectory;

/**

* Singleton for input parsing from a command line.

*

*

* @author parks

*

*/

public class InputParser {

private static InputParser me = null;

private Scanner inp;

private String line;

private Direction direction;

private String noun;

private String verb;

private ItemCommand itemCommand;

private String cCaveItemName;

private InputType inputType;

/**

* Singleton for getting input and parsing it.

*

* The general form of input is

*

*

*

* where is the action to take and the item to be manipulated or

* something that qualifies the .

*

*

*

* Examples are

*

* go east

* get lamp

* drop food

*

* The s are classified into "move" actions ("go") or inventory manipulation

* ("get," "drop"), or requests to restate current information ("look"),

* or "other" for commands that are special and must be processed by special code

* somewhere else.

*

* "Move" commands have special processing. If only a single word is entered

* that is a direction, the "move" classification is assumed. Thus

*

* "go ne" and "ne"

*

* are synonyms.

*

*

* NOTE: need to add lock for multi-tasking access.

*/

private InputParser() {

inp = new Scanner(System.in);

}

/**

* Access the input parser object. We create one if necessary,

* and simply return the one and only existing InputParser object

* if it was created already.

*

* @return the input parser to handle user input

*/

public static synchronized InputParser getInputParser() {

if (me == null)

me = new InputParser();

return me;

}

/**

* Read the next input from the user.

*

* I wonder if this method should be combined with the

* determineType method below?

*/

public void readInput() {

line = inp.nextLine();

inputType = parseInput();

}

public InputType getInputType() {

return inputType;

}

private void parseSingleWord() {

Direction d = Direction.findSynonym(verb);

if (d != Direction.UNKNOWN) {

inputType = InputType.MOVE;

itemCommand = ItemCommand.UNKNOWN;

direction = d;

}

}

/**

* Parse the input as best we can.

*

* @return value of InputType. InputType.OTHER is returned if the

* input was not recognized.

*/

private InputType parseInput() {

verb = "";

noun = "";

direction = Direction.UNKNOWN;

itemCommand = ItemCommand.UNKNOWN;

ItemDirectory itemDirec = ItemDirectory.getInstance();

int numInputs = 1;

Scanner parseLine = new Scanner(line);

if (parseLine.hasNext()) {

verb = parseLine.next();

}

if (parseLine.hasNext()) {

noun = parseLine.next();

numInputs++;

}

parseLine.close();

if (numInputs == 1) {

parseSingleWord();

return inputType;

}

// else parseTwoWords();

// if anything in the line looks like a direction (or synonym),

// we'll assume we're moving.

direction = Direction.findSynonym(verb);

if (direction != Direction.UNKNOWN) {

return InputType.MOVE;

}

direction = Direction.findSynonym(noun);

if (direction != Direction.UNKNOWN) {

return InputType.MOVE;

}

itemCommand = ItemCommand.findItemCommand(verb);

if ((itemCommand == ItemCommand.DROP || itemCommand == ItemCommand.GET) && itemDirec.contains(noun)) {

cCaveItemName = noun;

return InputType.INVENTORY;

}

// yuck. Needs to support NLS

if ("l".equalsIgnoreCase(verb) || "look".equalsIgnoreCase(verb)) return InputType.LOOK;

cCaveItemName = noun;

return InputType.OTHER;

}

/**

* Getter for the parsed direction to move

* @return Direction value. Direction.UNKNOWN if the input was not a "move" command.

*/

public Direction getDirection() {

return direction;

}

/**

* Getter for the first word of user input. This method is always

* valid, but only useful for OTHER inputs.

*

* @return the first word of user input.

*/

public String getVerb() {

return verb;

}

/**

* Getter for the second word of user input. This method is always

* valid, but only useful for OTHER inputs.

*

* @return the second word of user input, or the empty string if no second word was given.

*/

public String getNoun() {

return noun;

}

/**

* Getter for the entire line of user input.

*

* @return the line of user input

*/

public String getLine() {

return line;

}

/**

* This accessor is valid if and only if the user entered an inventory-related

* command, such as "get lamp." It returns the command (such as GET) entered by the user.

*

* @return the ItemCommand value (such as GET) entered by the user if an inventory-related

* command was entered. ItemCommand.UNKNOWN otherwise.

*/

public ItemCommand getItemCommand() {

return itemCommand;

}

/**

* This accessor is valid if and only if the user entered an inventory-related

* command, such as "get lamp." It returns the object to be manipulated.

*

* @return the CCaveItemConfig value (such as "KEYS") that the user wishes to manipulate,

* if an inventory-related command was entered. CCaveItemConfig.UNKNOWN otherwise.

*/

public String getcCaveItemName() {

return cCaveItemName;

}

}

aveTestMain Class:

import java.io.IOException;

import edu.waketech.ccave.common.Direction;

/**

* A place with a main method where we can code some tests of our cave code.

*

* @author parks

*

*/

public class CaveTestMain {

public static void main(String[] args) throws IOException {

// First some sanity checks.

// CCaveMap caveMap = CCaveMap.accessMap();

Spelunker me = new Spelunker("endofroad");

System.out.println(me.getLongDescription());

me.move(Direction.S);

System.out.println(me.getLongDescription());

me.move(Direction.N);

System.out.println(me.getLongDescription());

me.move(Direction.E);

System.out.println(me.getLongDescription());

}

}

Cave Class:

import java.io.IOException;

/**

* Main method and user interface for our console-based Colossal Cave Adventure

* Game.

*

* @author parks

*

*/

public class Cave {

public static final String START_ROOM = "end_of_road";

public static void main(String[] args) throws IOException {

// Let's start to play the game.

Spelunker caveMan;

caveMan = new Spelunker(START_ROOM);

InputParser playerInput = InputParser.getInputParser();

boolean running = true;

while (running) {

System.out.println(caveMan.getLongDescription());

playerInput.readInput();

if (playerInput.getInputType() == InputType.MOVE) caveMan.move(playerInput.getDirection());

else if (playerInput.getInputType() == InputType.LOOK) System.out.println(caveMan.getLongDescription());

else if (playerInput.getInputType() == InputType.INVENTORY) {

ItemCommand cmd = playerInput.getItemCommand();

String item = playerInput.getcCaveItemName();

caveMan.changeInventory(cmd, item);

}

else if (playerInput.getInputType() == InputType.OTHER) {

ItemCommand cmd = playerInput.getItemCommand();

String item = playerInput.getcCaveItemName();

caveMan.otherCommand(cmd, item);

}

}

}

}

EndofRoad Class (location):

public class EndOfRoad extends CCaveRoom {

public static final String MY_NAME = "end of road";

public EndOfRoad() {

super(MY_NAME);

}

}

Bed Class (Item):

public class Bed extends CCaveItem {

public static final String MY_NAME = "bed";

public Bed() {

super(MY_NAME);

}

}

endofroad propeties file:

longdescription = End of road shortdescription = end nwn = end_of_road

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!