Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.89 KB | None | 0 0
  1. Note to JT: This is my Rooms class:
  2. import java.util.Set;
  3. import java.util.HashMap;
  4. import java.util.Iterator;
  5. import java.io.IOException;
  6. import java.util.ArrayList;
  7. /**
  8. * Class Room - a room in an adventure game.
  9. *
  10. * This class is part of the "World of Zuul" application.
  11. * "World of Zuul" is a very simple, text based adventure game.
  12. *
  13. * A "Room" represents one location in the scenery of the game. It is
  14. * connected to other rooms via exits. For each existing exit, the room
  15. * stores a reference to the neighboring room.
  16. *
  17. * @author Michael Kolling and David J. Barnes
  18. * @version 2008.03.30
  19. */
  20.  
  21. public class Room
  22. {
  23. private String description;
  24. private HashMap<String, Room> exits; // stores exits of this room.
  25. public ArrayList<Item> roomItems;
  26.  
  27.  
  28.  
  29.  
  30. /**
  31. * Create a room described "description". Initially, it has
  32. * no exits. "description" is something like "a kitchen" or
  33. * "an open court yard".
  34. * @param description The room's description.
  35. */
  36. public Room(String description)
  37. {
  38. this.description = description;
  39. exits = new HashMap<String, Room>();
  40. roomItems = new ArrayList<Item>();
  41.  
  42. }
  43. /**
  44. *
  45. */
  46. public void addItemToRoom(Item item)
  47. {
  48. roomItems.add(item);
  49.  
  50. }
  51. /**
  52. * Define an exit from this room.
  53. * @param direction The direction of the exit.
  54. * @param neighbor The room to which the exit leads.
  55. */
  56. public void setExit(String direction, Room neighbor)
  57. {
  58. exits.put(direction, neighbor);
  59. }
  60.  
  61. /**
  62. * @return The short description of the room
  63. * (the one that was defined in the constructor).
  64. */
  65. public String getShortDescription()
  66. {
  67. return description;
  68. }
  69.  
  70. /**
  71. * Return a description of the room in the form:
  72. * You are in the kitchen.
  73. * Exits: north west
  74. * @return A long description of this room
  75. */
  76. public String getLongDescription()
  77. {
  78. return "You are " + description + ".\n" + getExitString();
  79. }
  80.  
  81. /**
  82. * Return a string describing the room's exits, for example
  83. * "Exits: north west".
  84. * @return Details of the room's exits.
  85. */
  86. private String getExitString()
  87. {
  88. String returnString = "Exits:";
  89. Set<String> keys = exits.keySet();
  90. for(String exit : keys) {
  91. returnString += " " + exit;
  92. }
  93. return returnString;
  94. }
  95.  
  96. /**
  97. * Return the room that is reached if we go from this room in direction
  98. * "direction". If there is no room in that direction, return null.
  99. * @param direction The exit's direction.
  100. * @return The room in the given direction.
  101. */
  102. public Room getExit(String direction)
  103. {
  104. return exits.get(direction);
  105. }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement