Advertisement
mnaufaldillah

Room Tugas 6

Nov 24th, 2020
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.72 KB | None | 0 0
  1. /**
  2.  * Class Room - a room in an adventure game.
  3.  *
  4.  * This class is the main class of the "World of Zuul"
  5.  * application.
  6.  * "World of Zuul" is a very simple, text based
  7.  * adventure game.
  8.  * A "Room" represents one location in the scenery of
  9.  * the game. It is connected to other rooms via exits. The exits are
  10.  * labelled north, east, south, west. For each direction, the room
  11.  * stores a reference to the neighboring room, or null if there is no exit
  12.  * in that direction.
  13.  *
  14.  * @author Muhammad Naufaldillah
  15.  * @version 24 November 2020
  16.  */
  17. public class Room
  18. {
  19.     public String description;
  20.     public Room northExit;
  21.     public Room southExit;
  22.     public Room eastExit;
  23.     public Room westExit;
  24.    
  25.     /**
  26.      * Create a room described "description".
  27.      * Initially, it has no exits. "description" is something like "a
  28.      * kitchen" or "an open court yard".
  29.      */
  30.     public Room(String description)
  31.     {
  32.         this.description = description;
  33.     }
  34.    
  35.     /**
  36.      * Define the exits of this room. Every direction
  37.      * either leads to another room or is null (no exit there).
  38.      */
  39.     public void setExits(Room north, Room east, Room south, Room west)
  40.     {
  41.         if(north != null)
  42.         {
  43.             northExit = north;
  44.         }
  45.         if(east != null)
  46.         {
  47.             eastExit = east;
  48.         }
  49.         if(south != null)
  50.         {
  51.             southExit = south;
  52.         }
  53.         if(west != null)
  54.         {
  55.             westExit = west;
  56.         }
  57.     }
  58.    
  59.     /**
  60.      *  Return the description of the room (the one that
  61.      *  was defined in the constructor).
  62.      */
  63.     public String getDescription()
  64.     {
  65.         return description;
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement