phamt

TransporterRoom + Scenario class Zuul

Feb 27th, 2018 (edited)
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.38 KB | None | 0 0
  1. package edu.pcc.cis.zuul;
  2.  
  3.  
  4. import java.util.ArrayList;
  5.  
  6. import java.util.Random;
  7.  
  8. /**
  9.  * Represents a game scenario including connected rooms and items
  10.  *
  11.  * @author Tony Pham
  12.  * @version 2018.02.26
  13.  */
  14. public class Scenario
  15. {
  16.     private ArrayList<Room> rooms;
  17.  
  18.  
  19.     private Room startRoom;
  20.  
  21.     private Room currentRoom;
  22.  
  23.     private Room transporterRoom;
  24.  
  25.     private Random random;
  26.  
  27.     /**
  28.      * Constructor for objects of class Scenario
  29.      */
  30.  
  31.     public Scenario()
  32.     {
  33.         random = new Random();
  34.  
  35.         startRoom = new Room("");
  36.  
  37.         currentRoom = new Room("");
  38.  
  39.         transporterRoom = new Room("");
  40.  
  41.         // Set up your rooms, exits, and items
  42.         // Move code from Game.createRooms here
  43.  
  44.         Room tardis, entrance, policestation, club, lab, cityhall, hospital, center, cellar, watchtower;
  45.  
  46.         // create the rooms
  47.         tardis = new TransporterRoom("outside the main entrance of town, you stumble upon a strange blue phone booth"); //problem
  48.         entrance = new Room("at the main entrance of town, a thick blanket fog covers the entirety of town,");
  49.         entrance.addItem("and found a dirty Journal", 5);
  50.         cellar = new Room("down into the cellar the smell of decomposing matter is strong,");
  51.         cellar.addItem("and found a folder", 2);
  52.         watchtower = new Room("up in the watchtower, it is cold and you can't see anything thanks to the fog,");
  53.         watchtower.addItem("and found a pair of binoculars", 4);
  54.         policestation = new Room("in the police station, you find find evidence of a gunfight that left bullet holes scattered throughout the place,");
  55.         policestation.addItem("and found a gun", 6);
  56.         club = new Room("in the local club, where you find broken bottles scattered around the premises covered in strange black goo,");
  57.         club.addItem("and found a water flask", 3);
  58.         lab = new Room("in the science lab, you find broken glass and the signs of an explosion,");
  59.         lab.addItem("and found a vial of strange liquid", 1);
  60.         cityhall = new Room("in the mayor's office, you find papers strewn all over the place,");
  61.         cityhall.addItem("and found a notebook full of notes", 2);
  62.         hospital = new Room("in the hospital, you find signs of a struggle along with black goo splattered all over the place along with the sound of something scratching against one of the doors,");
  63.         hospital.addItem("and found a small first-aid kit along with a stash of granola bars", 7);
  64.         center = new Room("in the center of town, you find signs of a huge accident along with cars that are either burnt out are have been broken into. You find black goo on some of the broken windows.");
  65.         center.addItem("and found a flashlight", 2);
  66.  
  67.  
  68.         // initialise room exits
  69.         tardis.setExit("south", entrance );
  70.  
  71.         entrance.setExit("east", policestation);
  72.         entrance.setExit("south", center);
  73.         entrance.setExit("north", tardis );
  74.  
  75.         policestation.setExit("up", watchtower);
  76.         policestation.setExit("west", entrance);
  77.  
  78.         club.setExit("north", center);
  79.  
  80.         lab.setExit("north", hospital);
  81.         lab.setExit("down", cellar);
  82.  
  83.         cityhall.setExit("east", center);
  84.  
  85.         hospital.setExit("west", center);
  86.         hospital.setExit("south", lab);
  87.  
  88.         center.setExit("north", entrance);
  89.         center.setExit("east", hospital);
  90.         center.setExit("south", club);
  91.         center.setExit("west", cityhall);
  92.  
  93.         cellar.setExit("up", lab);
  94.  
  95.         watchtower.setExit("down", policestation);
  96.  
  97.         // Set the start room
  98.  
  99.         startRoom = entrance;  // start game outside
  100.  
  101.  
  102.         // Create the rooms ArrayList and add all your rooms to it
  103.  
  104.         rooms = new ArrayList<Room>();
  105.         rooms.add(entrance);
  106.         rooms.add(policestation);
  107.         rooms.add(club);
  108.         rooms.add(lab);
  109.         rooms.add(cityhall);
  110.         rooms.add(hospital);
  111.         rooms.add(center);
  112.         rooms.add(cellar);
  113.         rooms.add(watchtower);
  114.         rooms.add(tardis);
  115.  
  116.     }
  117.  
  118.     /**
  119.      * @return  the start room for this scenario
  120.      */
  121.     public Room getStartRoom()
  122.     {
  123.         return this.startRoom;
  124.     }
  125.  
  126.     /**
  127.      * @return  a random room from this scenario
  128.      */
  129.     public Room getRandomRoom()
  130.     {
  131.         return rooms.get(random.nextInt(rooms.size()));
  132.     }
  133. }
  134. ///////////////////////////////////////////////////////////////////////////////////////////////////////
  135.  
  136. package edu.pcc.cis.zuul;
  137.  
  138. public class TransporterRoom extends Room{
  139.  
  140.     private Scenario scenario;
  141.     private String description;
  142.  
  143.     /**
  144.      * initialize TransporterRoom
  145.      * @param description
  146.      * @param  scenario
  147.      */
  148.     public TransporterRoom(String description, Scenario scenario) {
  149.         //this.description = description;
  150.         //scenario = new Scenario();
  151.         super(description);
  152.         this.scenario = scenario;
  153.     }
  154.  
  155.  
  156.  
  157.     /**
  158.      *
  159.      * @return A random room using the Scenario given in this class's constructor.
  160.      */
  161.     private Room findRandomRoom()
  162.     {
  163.        return scenario.getRandomRoom();
  164.     }
  165.  
  166.     /**
  167.      * @return similar string as Room class, but with an extra message
  168.      */
  169.     @Override
  170.     public String getExitString() {
  171.         return super.getExitString() + "\nAlso, the doorknob seems to be glowing...";
  172.     }
  173. }
Add Comment
Please, Sign In to add comment