Skip to content

Commit

Permalink
Changed exits to their own class, yeah.
Browse files Browse the repository at this point in the history
  • Loading branch information
silentdragoon committed May 2, 2011
1 parent 05bbaf4 commit 34f8de1
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion CommandWords.java
Expand Up @@ -13,7 +13,7 @@ public class CommandWords
{
// a constant array that holds all valid command words
private static final String[] validCommands = {
"go", "quit", "help", "take", "drop", "trade", "examine"
"go", "quit", "help", "take", "drop", "trade", "examine", "lock", "unlock"
};

/**
Expand Down
5 changes: 1 addition & 4 deletions Game.java
Expand Up @@ -66,11 +66,8 @@ private void createRooms()
lab.setItem("gold", "just some gold, sitting around");

player.addInventory("bagel", "half a blueberry bagel");

// TODO: Figure out this NPC thing.


outside.addNPC("The Cheat", "A helpful porter", "key", "a sweet key");
outside.addNPC("Dwarf", "A helpful Dwarf", "key", "a sweet key");

player.setCurrentRoom(outside); // start game outside
}
Expand Down
7 changes: 5 additions & 2 deletions Player.java
Expand Up @@ -54,8 +54,11 @@ public String getExamineString(String name)
{
String returnString = "You examine the " + name + ".\n";
Item temp = inventory.get(name);
returnString += "It's " + temp.getDescription() + ".";
return returnString;
if (temp != null) {
returnString += "It's " + temp.getDescription() + ".";
return returnString;
}
return "You can only examine items in your inventory.";
}

public void addInventory(String name, String description)
Expand Down
9 changes: 5 additions & 4 deletions Room.java
Expand Up @@ -19,7 +19,7 @@
public class Room
{
private String description;
private HashMap<String, Room> exits; // stores exits of this room.
private HashMap<String, Exit> exits; // stores exits of this room.
private HashMap<String, Item> items; // stores items of this room.
private HashMap<String, NPC> npcs;

Expand All @@ -31,7 +31,7 @@ public class Room
public Room(String description)
{
this.description = description;
exits = new HashMap<String, Room>();
exits = new HashMap<String, Exit>();
items = new HashMap<String, Item>();
npcs = new HashMap<String, NPC>();
}
Expand Down Expand Up @@ -91,7 +91,8 @@ public Item delItem(String name)
*/
public void setExit(String direction, Room neighbor)
{
exits.put(direction, neighbor);
Exit temp = new Exit(direction, neighbor);
exits.put(direction, temp);
}

/**
Expand Down Expand Up @@ -150,7 +151,7 @@ private String getNPCString()
*/
public Room getExit(String direction)
{
return exits.get(direction);
return exits.get(direction).getNeighbor();
}

public Item getItem(String name)
Expand Down

0 comments on commit 34f8de1

Please sign in to comment.