Room.java (1611B)
1 package Monster; 2 3 import java.util.*; 4 5 public class Room { 6 private String name; 7 private Room north, south, east, west; 8 private ArrayList<Treasure> treasures; 9 10 public Room(String name) { this.name = name; } 11 12 public Room(String name, Room north, Room south, Room east, Room west) { 13 this.name = name; 14 this.north = north; 15 this.south = south; 16 this.east = east; 17 this.west = west; 18 treasures = new ArrayList<>(); 19 } 20 21 public void setNorth(Room north) { this.north = north; } 22 public void setSouth(Room south) { this.south = south; } 23 public void setEast(Room east) { this.east = east; } 24 public void setWest(Room west) { this.west = west; } 25 26 public Room getNorth() { return this.north; } 27 public Room getSouth() { return this.south; } 28 public Room getEast() { return this.east; } 29 public Room getWest() { return this.west; } 30 31 public String getName() { return this.name; } 32 33 // 34 // NEW FEATURE 35 // 36 37 /** 38 * Add a new treasure to the list of treasures in the room 39 * @param t the new treasure to be added 40 */ 41 public void addTreasure(Treasure t) { 42 this.treasures.add(t); 43 } 44 45 /** 46 * Get the number of treasures in the room 47 * @return The number of treasures 48 */ 49 public int numTreasures() { 50 return this.treasures.size(); 51 } 52 53 /** 54 * Print all the treasures in a Room 55 */ 56 public void printTreasures() { 57 for (Treasure t : treasures) { 58 System.out.println(t.toString()); 59 } 60 } 61 62 /** 63 * Remove a treasure from a room 64 * @param i The index of the treasure to remove 65 * @return The that was removed 66 */ 67 public Treasure removeTreasure(int i) { 68 return this.treasures.remove(i); 69 } 70 };