- /*
- * 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;
- public class Organ
- {
- private String description;
- private HashMap<Organ> exits;
- /* private Organ anteriorExit;
- private Organ posteriorExit;
- private Organ ventralExit;
- private Organ dorsalExit;
- private Organ medialExit;
- private Organ distalExit;*/
- /**
- * 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 <Organ>();
- }
- /**
- * Define the exits of this room. Every direction either leads
- * to another room or is null (no exit there).
- */
- public void setExits(Organ anterior, Organ posterior, Organ ventral, Organ dorsal, Organ medial,
- Organ distal)
- {
- if (anterior != null)
- exits.put("anterior", anterior);
- if (posterior != null)
- exits.put("posterior", posterior);
- if (ventral != null)
- exits.put("ventral", ventral);
- if (dorsal != null)
- exits.put("dorsal", dorsal);
- if (medial != null)
- exits.put("medial", medial);
- if (distal != null)
- exits.put ("distal", distal);
- /* if(anterior != null)
- anteriorExit = anterior;
- if(posterior != null)
- posteriorExit = posterior;
- if(ventral != null)
- ventralExit = ventral;
- if(dorsal != null)
- dorsalExit = dorsal;
- if(medial != null)
- medialExit = medial;
- if(distal != null)
- distalExit = distal;*/
- }
- /**
- * 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);
- /*if (direction.equals("anterior"))
- return anteriorExit;
- if (direction.equals ("posterior"))
- return posteriorExit;
- if (direction.equals ("ventral"))
- return ventralExit;
- if (direction.equals ("dorsal"))
- return dorsalExit;
- if (direction.equals ("medial"))
- return medialExit;
- if (direction.equals ("distal"))
- return distalExit;
- return null;*/
- }
- public String getExitString()
- {
- String exitString = ("You are " + getDescription() + "\n");
- if(getExit("anterior") != null)
- exitString += "anterior ";
- if(getExit ("posterior") != null)
- exitString += "posterior ";
- if(getExit("ventral") != null)
- exitString += "ventral ";
- if(getExit ("dorsal") != null)
- exitString += "dorsal ";
- if(getExit("medial") != null)
- exitString += "medial ";
- if(getExit("distal") != null)
- exitString += ("distal ");
- return exitString;
- /*System.out.println("You are " + getDescription());
- System.out.print("Exits: ");
- if(getExit("anterior") != null)
- System.out.print("anterior ");
- if(getExit ("posterior") != null)
- System.out.print("posterior ");
- if(getExit("ventral") != null)
- System.out.print("ventral ");
- if(getExit ("dorsal") != null)
- System.out.print("dorsal ");
- if(getExit("medial") != null)
- System.out.print("medial");
- if(getExit("distal") != null)
- System.out.print("distal");
- System.out.println();*/
- }
- }