001import java.util.HashMap; 002import java.util.Set; 003import java.util.Iterator; 004 005/** 006 * Class Room - a room in an adventure game. 007 * 008 * This class is part of the "Pere-noel" application. 009 * "Pere Noel" 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. The exits are labelled north, 013 * east, south, west. For each direction, the room stores a reference 014 * to the neighboring room, or null if there is no exit in that direction. 015 * 016 * @author Célia PRIOL & Benoît CHAUVEAU 017 */ 018public class Room 019{ 020 public String description; 021 private HashMap<String, Room> exits; 022 private String imageName; 023 // private Item aItems; 024 private HashMap<Item,Integer> ListeObjets; 025 private ItemList aItems; 026 027 /** 028 * Create a room described "description". Initially, it has 029 * no exits. "description" is something like "a kitchen" or 030 * "an open court yard". 031 * @param description The room's description. 032 */ 033 public Room(String description, String image) 034 { 035 this.description = description; 036 exits = new HashMap<String, Room>();// création de l'objet exits 037 imageName = image; 038 this.ListeObjets = new HashMap<Item,Integer>(); 039 aItems = new ItemList(); 040 } 041 042 /** 043 * Define the exits of this room. Every direction either leads 044 * to another room or is null (no exit there). 045 * @param north The north exit. 046 * @param east The east east. 047 * @param south The south exit. 048 * @param west The west exit. 049 */ 050 public void setExits(String direction, Room neighbor) 051 { 052 exits.put(direction,neighbor); 053 } 054 055 public void addItem(String pName,Item pItem) 056 { 057 aItems.addItem(pName,pItem); 058 } 059 060 /** 061 * @return The description of the room. 062 */ 063 public String getDescription() 064 { 065 return description; 066 } 067 068 /** 069 * 7.6 070 */ 071 public Room getExit(String direction) 072 { 073 return exits.get(direction); 074 } 075 076 /** 077 * Renvoie une description des sorties de la 078 * pièce, par exemple, "Sorties : nord ouest". 079 * @return Une description des sorties possibles 080 */ 081 public String getExitString() 082 { 083 String returnString ="\n"+"Les sorties sont :"; 084 Set<String> keys = exits.keySet(); 085 for(String exit : keys) { 086 returnString += " "+ exit; 087 } 088 return returnString; 089 090 } 091 092 /** 093 * Definit une sortie pour cette pièce. 094 * @param direction La direction de la sortie. 095 * @aram neighbor La salle dans la direction donnée. 096 */ 097 public void setExit(String direction,Room neighbor) 098 { 099 exits.put(direction, neighbor); 100 } 101 102 /** 103 * Definit une sortie pour cette pièce. 104 * @param direction La direction de la sortie. 105 * @param neighbor La salle dans la direction donnée. 106 */ 107 public void setItem(String pName,Item pItem) 108 { 109 aItems.addItem(pName, pItem); 110 } 111 112 /** 113 *7.11 114 *Renvoie une description detaille de cette piece sous la forme : 115 * Vous etes dans la cuisine. 116 * Sorties : nord ouest 117 *@return une description de la piece, avec les sorties 118 */ 119 public String getLongDescription () 120 {return"\n"+"Tu es"+" "+ description+ ". "+ getExitString()+". " + getObjetString()+"\n" ; 121 } 122 123 124 125 /** 126 * Return a string describing the room's image name 127 */ 128 public String getImageName() 129 { 130 return imageName; 131 } 132 133 /** 134 * Definir les objets de la piece sous forme de liste 135 */ 136 public void setObjets(Item pItem, int pNombre) 137 { 138 ListeObjets.put(pItem,pNombre); 139 } 140 141 142 private String getObjetString() 143 { 144 String returnString = ""; 145 Set<String> keys=aItems.getkeySet(); 146 for ( String vItem : keys) 147 { 148 149 Item trueItem = aItems.getItem(vItem); 150 returnString +=trueItem.getLongItem1Description(); 151 } 152 return returnString ; 153 154 } 155 156 157 /** 158 * Accessor 159 */ 160 public Item getItem(String pItem) 161 { 162 return aItems.getItem(pItem); 163 } 164 165 public void removeItem(String pName) 166 { 167 aItems.removeItem(pName); 168 } 169 170 private int getNombreObjet(Item pItem) 171 { 172 int vNombre = ListeObjets.get(pItem); 173 return vNombre; 174 } 175} 176