001import java.util.Set; 002import java.util.HashMap; 003import java.util.Iterator; 004 005/** 006 * Class Room - a room in an adventure game. 007 * 008 * This class is part of the "World of Zuul" application. 009 * "World of Zuul" is a very simple, text based adventure game. 010 * 011 * A "Room" represents one location in the scenery of the game. It is 012 * connected to other rooms via exits. For each existing exit, the room 013 * stores a reference to the neighboring room. 014 * 015 * @author Michael Kolling and David J. Barnes and Alban FERRACANI 016 * @version 1.0 (February 2002) DBMOD:04/04/2008, 2019, AF edited (2021) 017 */ 018 019public class Room 020{ 021 private String description; 022 private HashMap<String,Room> exits; // stores exits of this room 023 /**/ private String aImageName; 024 025 private Item aItem; 026 // private HashMap<String,Item> aListeItems; 027 private ItemList aInventoryRoom; 028 private boolean aTrapDoor; 029 private String aEnigme; 030 private String aNomRoom; 031 032 /** 033 * Create a room described "description" with a given image. 034 * Initially, it has no exits. "description" is something like 035 * "in a kitchen" or "in an open court yard". 036 */ 037 public Room(final String pNomRoom, final String pDescription /**/, final String pImage, final String pEnigme) 038 { 039 this.description = pDescription; 040 exits = new HashMap<String,Room>(); 041 /**/ this.aImageName = pImage; 042 043 //this.aItem = null; 044 //this.aListeItems = new HashMap<String,Item>(); 045 this.aInventoryRoom = new ItemList(); 046 this.aTrapDoor = false; 047 this.aEnigme = pEnigme; 048 this.aNomRoom = pNomRoom; 049 } 050 051 /** 052 * Define an exit from this room. 053 */ 054 public void setExit(String direction, Room neighbor, final boolean pTrapDoor) 055 { 056 this.exits.put(direction, neighbor); 057 this.aTrapDoor = pTrapDoor; 058 } //setExit() 059 060 /** 061 * Return the description of the room (the one that was defined in the 062 * constructor). 063 */ 064 public String getShortDescription() 065 { 066 return description; 067 } //getShortDescription() 068 069 /** 070 * setItem 071 */ 072 public void setItem(final Item pItem) 073 { 074 this.aItem = pItem; 075 } //setItem() 076 077 078 /** 079 * Return a long description of this room, in the form: 080 * You are in the kitchen. 081 * Exits: north west 082 */ 083 public String getLongDescription() 084 { 085 //return "GAME ITEMS" + this.aItem.getDescription(); 086 //String vNomItem = this.aItem.getDescription(); 087 //return "-----------------------------S O R T I E S -------------------------------" +".\n" + 088 //"Vous êtes " + description + ".\n" + getExitString() + (this.aItem!=null? ".\n" +this.aItem.getDescription():".\nPas d'item dans cette pièce"); 089 return "-----------------------------S O R T I E S -------------------------------" +"\n" + 090 "Vous êtes " + description + ".\n" + getExitString() + "\n"+ this.getItemsDescription(); 091 } //getLongDescription() 092 093 /** 094 * Return a string describing the room's exits, for example 095 * "Exits: north west". 096 */ 097 private String getExitString() 098 { 099 StringBuilder returnString = new StringBuilder( "Sorties :" ); 100 for ( String vS : exits.keySet() ) 101 returnString.append( " " + vS ); 102 return returnString.toString(); 103 } //getExitString() 104 105 /** 106 * Return the room that is reached if we go from this room in direction 107 * "direction". If there is no room in that direction, return null. 108 */ 109 public Room getExit(String direction) 110 { 111 return exits.get(direction); 112 } //getExit() 113 114 /** 115 * Return a string describing the room's image name 116 */ 117 /**/ public String getImageName() 118 /**/ { 119 /**/ return this.aImageName; 120 /**/ } 121 122 /** 123 * Pour ajouter des items dans la pièce. 124 */ 125 public void addItem(final String pNomItem, final Item pItem) 126 { 127 //this.aListeItems.put(pNomItem, pItem); 128 this.aInventoryRoom.putItem(pNomItem, pItem); 129 } //addItem() 130 131 /** 132 * Pour retirer des items dans la pièce. 133 */ 134 public void removeItem(final String pNomItem, final Item pItemRetire) 135 { 136 this.aInventoryRoom.removeItem(pNomItem); 137 } //removeItem() 138 139 /** 140 * Retourne la description des items. 141 */ 142 private String getItemsDescription() 143 { 144 String vTest = this.aInventoryRoom.getItemString(); 145 return vTest; 146 } //getItemsDescription() 147 148 /** 149 * getItem 150 */ 151 public Item getItem(String pItem) 152 { 153 return this.aInventoryRoom.getCurrentItem(pItem); 154 } //getItem() 155 156 /** 157 * Accesseur de trapdoor. 158 */ 159 public boolean getTrapDoor() 160 { 161 return this.aTrapDoor; 162 } //getTrapDoor() 163 164 /** 165 * Accesseur des énigmes 166 */ 167 public String getEnigme(){ 168 return this.aEnigme; 169 } //getEnigme() 170 171 /** 172 * Accesseur de aNomRoom 173 */ 174 public String getNomRoom(){ 175 return this.aNomRoom; 176 } //getNomRoom() 177 178 /** 179 * Accesseur de ItemWin 180 */ 181 public String getItemWin(){ 182 return this.aInventoryRoom.getItemStringWin(); 183 } //getNomRoom() 184}