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 9th, 2010  |  syntax: None  |  size: 4.39 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.  
  17. public class Organ
  18. {
  19.     private String description;
  20.     private HashMap<Organ> exits;    
  21.     /* private Organ anteriorExit;
  22.     private Organ posteriorExit;
  23.     private Organ ventralExit;
  24.     private Organ dorsalExit;
  25.     private Organ medialExit;
  26.     private Organ distalExit;*/
  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 <Organ>();
  38.     }
  39.  
  40.     /**
  41.      * Define the exits of this room.  Every direction either leads
  42.      * to another room or is null (no exit there).
  43.      */
  44.     public void setExits(Organ anterior, Organ posterior, Organ ventral, Organ dorsal, Organ medial,
  45.                                          Organ distal)
  46.     {
  47.       if (anterior != null)
  48.         exits.put("anterior", anterior);
  49.       if (posterior != null)
  50.         exits.put("posterior", posterior);
  51.       if (ventral != null)
  52.         exits.put("ventral", ventral);
  53.       if (dorsal != null)
  54.         exits.put("dorsal", dorsal);
  55.       if (medial != null)
  56.         exits.put("medial", medial);
  57.       if (distal != null)
  58.         exits.put ("distal", distal);
  59.         /* if(anterior != null)
  60.             anteriorExit = anterior;
  61.         if(posterior != null)
  62.             posteriorExit = posterior;
  63.         if(ventral != null)
  64.             ventralExit = ventral;
  65.         if(dorsal != null)
  66.             dorsalExit = dorsal;
  67.         if(medial != null)
  68.             medialExit = medial;
  69.         if(distal != null)
  70.             distalExit = distal;*/
  71.            
  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.     /*if (direction.equals("anterior"))
  87.         return anteriorExit;
  88.     if (direction.equals ("posterior"))
  89.         return posteriorExit;
  90.     if (direction.equals ("ventral"))
  91.         return ventralExit;
  92.     if (direction.equals ("dorsal"))
  93.         return dorsalExit;
  94.     if (direction.equals ("medial"))
  95.         return medialExit;
  96.     if (direction.equals ("distal"))
  97.         return distalExit;
  98.         return null;*/
  99.        
  100.     }
  101.    
  102.     public String getExitString()
  103.     {
  104.        String exitString = ("You are " + getDescription() + "\n");
  105.             if(getExit("anterior") != null)
  106.                 exitString += "anterior ";
  107.             if(getExit ("posterior") != null)
  108.                 exitString += "posterior ";
  109.             if(getExit("ventral") != null)
  110.                exitString += "ventral ";
  111.             if(getExit ("dorsal") != null)
  112.                 exitString += "dorsal ";
  113.             if(getExit("medial") != null)
  114.                 exitString += "medial ";
  115.           if(getExit("distal") != null)
  116.                 exitString += ("distal ");
  117.             return exitString;
  118.        
  119.         /*System.out.println("You are " + getDescription());
  120.             System.out.print("Exits: ");
  121.             if(getExit("anterior") != null)
  122.                 System.out.print("anterior ");
  123.             if(getExit ("posterior") != null)
  124.                 System.out.print("posterior ");
  125.             if(getExit("ventral") != null)
  126.                 System.out.print("ventral ");
  127.             if(getExit ("dorsal") != null)
  128.                 System.out.print("dorsal ");
  129.             if(getExit("medial") != null)
  130.                 System.out.print("medial");
  131.           if(getExit("distal") != null)
  132.                 System.out.print("distal");
  133.             System.out.println();*/
  134.            
  135.            
  136.         }
  137.    
  138.  
  139. }