SHARE
TWEET

Untitled

a guest May 19th, 2017 43 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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 = generateGlucose();
  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.     public 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.       public void resetGlucoseLevel()
  63.       {
  64.           if (glucoseLevel > 0)
  65.           {
  66.               glucoseLevel -= 1;
  67.         }
  68.     }
  69.     /**
  70.      * Return the description of the room (the one that was defined
  71.      * in the constructor).
  72.      */
  73.     public String getDescription()
  74.     {
  75.         return description;
  76.     }
  77.    
  78.     public Organ getExit(String direction)
  79.     {
  80.         return exits.get (direction);      
  81.     }
  82.    
  83.     public String getLongDescription()
  84.         {
  85.             return "You are " + description + ".\n" + getExitString() + "\n" + "There is " + getGlucoseLevel()
  86.             + " glucose";
  87.         }
  88.     public String getExitString()
  89.     {
  90.         String returnString = "Exits: ";
  91.         Set keys = exits.keySet();
  92.             for (Iterator iter = keys.iterator(); iter.hasNext();)
  93.                 returnString += " " + iter.next();
  94.                 return returnString;
  95.             }
  96.                
  97.         }
RAW Paste Data
Challenge yourself this year...
Learn something new in 2017
Top