Ejemplo n.º 1
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;
 }
Ejemplo n.º 2
0
 /**
  * Add a given item. The name (id) of the item should be unique in the room.
  *
  * @param it - Item to be added
  * @return true if the action was completed.
  */
 public boolean addItem(Item it) {
   if (existsItem(it.getId())) {
     return false;
   } else {
     items.add(it);
     return true;
   }
 }
Ejemplo n.º 3
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
 }