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 3

By: ace on Mar 31st, 2010  |  syntax: None  |  size: 3.80 KB  |  hits: 9  |  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.  
  16. public class Organ
  17. {
  18.     private String description;
  19.     private Organ anteriorExit;
  20.     private Organ posteriorExit;
  21.     private Organ ventralExit;
  22.     private Organ dorsalExit;
  23.     private Organ medialExit;
  24.     private Organ distalExit;
  25.  
  26.     /**
  27.      * Create a room described "description". Initially, it has
  28.      * no exits. "description" is something like "a kitchen" or
  29.      * "an open court yard".
  30.      */
  31.     public Organ(String description)
  32.     {
  33.         this.description = description;
  34.     }
  35.  
  36.     /**
  37.      * Define the exits of this room.  Every direction either leads
  38.      * to another room or is null (no exit there).
  39.      */
  40.     public void setExits(Organ anterior, Organ posterior, Organ ventral, Organ dorsal, Organ medial,
  41.                                          Organ distal)
  42.     {
  43.         if(anterior != null)
  44.             anteriorExit = anterior;
  45.         if(posterior != null)
  46.             posteriorExit = posterior;
  47.         if(ventral != null)
  48.             ventralExit = ventral;
  49.         if(dorsal != null)
  50.             dorsalExit = dorsal;
  51.         if(medial != null)
  52.             medialExit = medial;
  53.         if(distal != null)
  54.             distalExit = distal;
  55.     }
  56.  
  57.     /**
  58.      * Return the description of the room (the one that was defined
  59.      * in the constructor).
  60.      */
  61.     public String getDescription()
  62.     {
  63.         return description;
  64.     }
  65.    
  66.     public Organ getExit(String direction)
  67.     {
  68.     if (direction.equals("anterior"))
  69.         return anteriorExit;
  70.     if (direction.equals ("posterior"))
  71.         return posteriorExit;
  72.     if (direction.equals ("ventral"))
  73.         return ventralExit;
  74.     if (direction.equals ("dorsal"))
  75.         return dorsalExit;
  76.     if (direction.equals ("medial"))
  77.         return medialExit;
  78.     if (direction.equals ("distal"))
  79.         return distalExit;
  80.         return null;
  81.     }
  82.    
  83.     public String getExitString()
  84.     {
  85.        String exitString = ("You are " + getDescription());
  86.             if(getExit("anterior") != null)
  87.                 exitString += "anterior ";
  88.             if(getExit ("posterior") != null)
  89.                 exitString += "posterior ";
  90.             if(getExit("ventral") != null)
  91.                exitString += "ventral ";
  92.             if(getExit ("dorsal") != null)
  93.                 exitString += "dorsal ";
  94.             if(getExit("medial") != null)
  95.                 exitString += "medial ";
  96.           if(getExit("distal") != null)
  97.                 exitString += ("distal ");
  98.             return exitString;
  99.        
  100.         /*System.out.println("You are " + getDescription());
  101.             System.out.print("Exits: ");
  102.             if(getExit("anterior") != null)
  103.                 System.out.print("anterior ");
  104.             if(getExit ("posterior") != null)
  105.                 System.out.print("posterior ");
  106.             if(getExit("ventral") != null)
  107.                 System.out.print("ventral ");
  108.             if(getExit ("dorsal") != null)
  109.                 System.out.print("dorsal ");
  110.             if(getExit("medial") != null)
  111.                 System.out.print("medial");
  112.           if(getExit("distal") != null)
  113.                 System.out.print("distal");
  114.             System.out.println();*/
  115.            
  116.            
  117.         }
  118.    
  119.  
  120. }