示例#1
0
  /**
   * Returns the room description and a list with the ids of the items and their description that
   * belongs to this room. <> <>
   *
   * @return The room description
   */
  public String getDescription() {
    String aux = "";
    String infoItems = "";
    Iterator<Item> it = this.items.iterator();
    if (it.hasNext()) {
      aux = this.description + Msg.room_items;
      ;
      while (it.hasNext()) {
        Item auxItem = it.next();
        infoItems = infoItems + auxItem.toString() + "\n";
      }
    } else aux = this.description + Msg.room_empty;

    return aux + infoItems;
  }
示例#2
0
 /**
  * Return true if the Item <> exists.
  *
  * @param id - Name of the item.
  * @return true if the room as an item with that name.
  */
 public boolean existsItem(String id) {
   Iterator<Item> it = items.iterator();
   while (it.hasNext()) {
     Item aux = it.next();
     if (aux.getId().equalsIgnoreCase(id)) return true;
   }
   return false; // NO SE HA ENCONTRADO EL ITEM CON ESE ID
 }
示例#3
0
 /**
  * Pick an item from the room and add it to the player's inventory.
  *
  * @param who - the player
  * @param id - the identifier of the item
  * @return true if the action was successfully performed.
  */
 public boolean pickItem(Player who, String id) {
   if (!existsItem(id)) {
     return false;
   } else {
     Iterator<Item> it = items.iterator();
     while (it.hasNext()) {
       Item aux = it.next();
       if (aux.getId().equalsIgnoreCase(id))
         if (who.addItem(aux)) {
           items.remove(aux);
           return true;
         } else return false;
     }
   }
   return false;
 }