Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

get exit string game class

By: ace on Apr 15th, 2010  |  syntax: None  |  size: 2.49 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. /*
  2.  * Class Room - a room in an adventure game.
  3.  *
  4.  * This class is part of the "World of Zuul" application.
  5.  * "World of Zuul" is a very simple, text based adventure game.  
  6.  *
  7.  * A "Room" represents one location in the scenery of the game.  It is
  8.  * connected to other rooms via exits.  The exits are labelled north,
  9.  * east, south, west.  For each direction, the room stores a reference
  10.  * to the neighboring room, or null if there is no exit in that direction.
  11.  *
  12.  * @author  Michael Kolling and David J. Barnes
  13.  * @version 1.0 (February 2002)
  14.  */
  15. import java.util.HashMap;
  16. import java.util.Iterator;
  17. import java.util.Set;
  18. import java.util.Random;
  19.  
  20. public class Organ
  21. {
  22.     private String description;
  23.     private HashMap<String, Organ> exits;  
  24.     private int glucose;
  25.     Random glucoseGenerator;
  26.     private int glucoseLevel;
  27.        
  28.  
  29.     /**
  30.      * Create a room described "description". Initially, it has
  31.      * no exits. "description" is something like "a kitchen" or
  32.      * "an open court yard".
  33.      */
  34.     public Organ(String description)
  35.     {
  36.         this.description = description;
  37.         exits = new HashMap <String, Organ>();
  38.         glucoseGenerator = new Random();
  39.         glucoseLevel = 3;
  40.     }
  41.  
  42.     /**
  43.      * Define the exits of this room.  Every direction either leads
  44.      * to another room or is null (no exit there).
  45.      */
  46.     public void setExit(String direction, Organ neighbor)
  47.     {
  48.         exits.put (direction, neighbor);          
  49.     }
  50.    
  51.     private int generateGlucose()
  52.         {
  53.             int glucoseLevel = glucoseGenerator.nextInt(3);
  54.             return glucoseLevel;
  55.         }
  56.  
  57.     public int getGlucoseLevel()
  58.         {
  59.             return glucoseLevel;
  60.         }
  61.     /**
  62.      * Return the description of the room (the one that was defined
  63.      * in the constructor).
  64.      */
  65.     public String getDescription()
  66.     {
  67.         return description;
  68.     }
  69.    
  70.     public Organ getExit(String direction)
  71.     {
  72.         return exits.get (direction);      
  73.     }
  74.    
  75.     public String getLongDescription()
  76.         {
  77.             return "You are " + description + ".\n" + getExitString();
  78.         }
  79.     public String getExitString()
  80.     {
  81.         String returnString = "Exits: ";
  82.         Set keys = exits.keySet();
  83.             for (Iterator iter = keys.iterator(); iter.hasNext();)
  84.                 returnString += " " + iter.next();
  85.                 return returnString;
  86.             }
  87.                
  88.         }