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 17th, 2010  |  syntax: None  |  size: 3.18 KB  |  hits: 6  |  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.     Random itemGenerator;
  28.     private boolean hasitem;  
  29.     private Item item;
  30.     /**
  31.      * Create a room described "description". Initially, it has
  32.      * no exits. "description" is something like "a kitchen" or
  33.      * "an open court yard".
  34.      */
  35.     public Organ(String description)
  36.     {
  37.         this.description = description;
  38.         exits = new HashMap <String, Organ>();
  39.         glucoseGenerator = new Random();
  40.         glucoseLevel = generateGlucose();
  41.         item = null;
  42.        
  43.        
  44.        
  45.     }
  46.  
  47.     /**
  48.      * Define the exits of this room.  Every direction either leads
  49.      * to another room or is null (no exit there).
  50.      */
  51.     public void setExit(String direction, Organ neighbor)
  52.     {
  53.         exits.put (direction, neighbor);          
  54.     }
  55.    
  56.     public int generateGlucose()
  57.         {
  58.             glucoseLevel = glucoseGenerator.nextInt(3);
  59.             return glucoseLevel;
  60.         }
  61.  
  62.     public int getGlucoseLevel()
  63.         {
  64.             return glucoseLevel;
  65.         }
  66.        
  67.       public void resetGlucoseLevel()
  68.       {
  69.           if (glucoseLevel > 0)
  70.           {
  71.               glucoseLevel -= 1;
  72.         }
  73.     }
  74.     /**
  75.      * Return the description of the room (the one that was defined
  76.      * in the constructor).
  77.      */
  78.     public String getDescription()
  79.     {
  80.         return description;
  81.     }
  82.    
  83.     public Organ getExit(String direction)
  84.     {
  85.         return exits.get (direction);      
  86.     }
  87.    
  88.     public String getLongDescription()
  89.         {
  90.             return "You are " + description + ".\n" + getExitString() + "\n" + "There is " + getGlucoseLevel()
  91.             + " glucose";
  92.         }
  93.     public String getExitString()
  94.     {
  95.         String returnString = "Exits: ";
  96.         Set keys = exits.keySet();
  97.             for (Iterator iter = keys.iterator(); iter.hasNext();)
  98.                 returnString += " " + iter.next();
  99.                 return returnString;
  100.             }
  101.            
  102.        public String itemCheck()
  103.        {
  104.            if (item == null)
  105.                 {
  106.                     return String "There are no items in this organ.";
  107.                 }
  108.            
  109.                 else
  110.                 {
  111.                     return item.getItemDescription();
  112.                 }
  113.             }
  114.                            
  115.         }