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