Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

bombsquad room2

By: ace on Jul 14th, 2010  |  syntax: None  |  size: 3.54 KB  |  hits: 8  |  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. import java.util.HashMap;
  2. /*
  3.  * Class Room - a room in an adventure game.
  4.  *
  5.  * This class is part of the "World of Zuul" application.
  6.  * "World of Zuul" is a very simple, text based adventure game.  
  7.  *
  8.  * A "Room" represents one location in the scenery of the game.  It is
  9.  * connected to other rooms via exits.  The exits are labelled north,
  10.  * east, south, west.  For each direction, the room stores a reference
  11.  * to the neighboring room, or null if there is no exit in that direction.
  12.  *
  13.  * @author  Michael Kolling and David J. Barnes
  14.  * @version 1.0 (February 2002)
  15.  */
  16.  
  17. public class Room
  18. {
  19.  
  20. private String description;
  21. private HashMap<String, Room> exits;
  22. /*private String description;
  23.     private Room northExit;
  24.     private Room southExit;
  25.     private Room eastExit;
  26.     private Room westExit;
  27. */
  28.    /**
  29. * Create a room described "description". Initially, it has
  30. * no exits. "description" is something like "a kitchen" or
  31. * "an open court yard".
  32. */
  33. public Room(String description)
  34. {
  35. this.description = description;
  36. exits = new HashMap();
  37. }
  38.  
  39. /**
  40. * Define the exits of this room. Every direction either leads
  41. * to another room or is null (no exit there).
  42. */
  43. public void setExits(Room north, Room east, Room south,
  44. Room west)
  45. {
  46. if(north != null)
  47. exits.put("north", north);
  48. if(east != null)
  49. exits.put("east", east);
  50. if(south != null)
  51. exits.put("south", south);
  52. if(west != null)
  53. exits.put("west", west);
  54. }
  55. /**
  56. * Return the room that is reached if we go from this room in
  57. * direction "direction". If there is no room in that
  58. * direction, return null.
  59. */
  60. public Room getExit(String direction)
  61. {
  62. return exits.get(direction);
  63. }
  64.  
  65. /**
  66. * Return the description of the room (the one that was defined
  67. * in the constructor).
  68. */
  69. public String getDescription()
  70. {
  71. return description;
  72. }
  73.  
  74.  
  75. /**
  76.      * Create a room described "description". Initially, it has
  77.      * no exits. "description" is something like "a kitchen" or
  78.      * "an open court yard".
  79.      */
  80.    /* public Room(String description)
  81.     {
  82.         this.description = description;
  83.     }*/
  84.  
  85.    /**
  86.      * Define the exits of this room.  Every direction either leads
  87.      * to another room or is null (no exit there).
  88.      */
  89.    /* public void setExits(Room north, Room east, Room south, Room west)
  90.     {
  91.         if(north != null)
  92.             northExit = north;
  93.         if(east != null)
  94.             eastExit = east;
  95.         if(south != null)
  96.             southExit = south;
  97.         if(west != null)
  98.             westExit = west;
  99.     }*/
  100.  
  101.     /**
  102.      * Return the description of the room (the one that was defined
  103.      * in the constructor).
  104.      */
  105.     /*public String getDescription()
  106.     {
  107.         return description;
  108.     }
  109.    
  110.     public Room getExit(String direction)
  111. {
  112. if(direction.equals("north"))
  113. return northExit;
  114. if(direction.equals("east"))
  115. return eastExit;
  116. if(direction.equals("south"))
  117. return southExit;
  118. if(direction.equals("west"))
  119. return westExit;
  120. return null;
  121. }*/
  122.  
  123.   public String getExitString(Room currentRoom)
  124.     {
  125.        String exitString = "";
  126.      
  127.      if(exits.get(direction)!= null)
  128.         {
  129.             exitString = "north ";
  130.         }
  131.      if(eastExit != null)
  132.             {
  133.                 exitString = exitString + "east ";
  134.             }
  135.      if(southExit != null)
  136.             {
  137.              exitString = exitString + "south ";
  138.             }
  139.      if(westExit != null)
  140.             {
  141.               exitString = exitString + "west ";
  142.              }
  143.                 return exitString;
  144.     }
  145.  
  146.  
  147. }