Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Class Room - a room in an adventure game.
- *
- * This class is part of the "World of Zuul" application.
- * "World of Zuul" is a very simple, text based adventure game.
- *
- * A "Room" represents one location in the scenery of the game. It is
- * connected to other rooms via exits. The exits are labelled north,
- * east, south, west. For each direction, the room stores a reference
- * to the neighboring room, or null if there is no exit in that direction.
- *
- * @author Michael Kolling and David J. Barnes
- * @version 1.0 (February 2002)
- */
- import java.util.HashMap;
- import java.util.Iterator;
- import java.util.Set;
- import java.util.Random;
- public class Organ
- {
- private String description;
- private HashMap<String, Organ> exits;
- private int glucose;
- Random glucoseGenerator;
- private int glucoseLevel;
- /**
- * Create a room described "description". Initially, it has
- * no exits. "description" is something like "a kitchen" or
- * "an open court yard".
- */
- public Organ(String description)
- {
- this.description = description;
- exits = new HashMap <String, Organ>();
- glucoseGenerator = new Random();
- glucoseLevel = generateGlucose();
- }
- /**
- * Define the exits of this room. Every direction either leads
- * to another room or is null (no exit there).
- */
- public void setExit(String direction, Organ neighbor)
- {
- exits.put (direction, neighbor);
- }
- public int generateGlucose()
- {
- int glucoseLevel = glucoseGenerator.nextInt(3);
- return glucoseLevel;
- }
- public int getGlucoseLevel()
- {
- return glucoseLevel;
- }
- public void resetGlucoseLevel()
- {
- if (glucoseLevel > 0)
- {
- glucoseLevel -= 1;
- }
- }
- /**
- * Return the description of the room (the one that was defined
- * in the constructor).
- */
- public String getDescription()
- {
- return description;
- }
- public Organ getExit(String direction)
- {
- return exits.get (direction);
- }
- public String getLongDescription()
- {
- return "You are " + description + ".\n" + getExitString() + "\n" + "There is " + getGlucoseLevel()
- + " glucose";
- }
- public String getExitString()
- {
- String returnString = "Exits: ";
- Set keys = exits.keySet();
- for (Iterator iter = keys.iterator(); iter.hasNext();)
- returnString += " " + iter.next();
- return returnString;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement