Example #1
0
 /** Verify that the room has the specified item */
 public Item checkItem(String itemName) {
   for (int x = 0; x < items.size(); x++) {
     if (items.get(x).getName().equals(itemName)) {
       return items.get(x);
     }
   }
   return null;
 }
Example #2
0
 /**
  * ?? Incomplete search -- search for particular types of items
  *
  * <p>This will eventually allow you to sift through the room for specific item types. Helpful if
  * a character has an item specific profession (locksmith is partial to keys) More helpful for my
  * main game though.
  */
 public String searchItemType() {
   StringBuffer temp;
   if (items.size() > 0) {
     temp = new StringBuffer("The room contains: ");
     for (int x = 0; x < items.size() - 1; x++) {
       temp.append(items.get(x).getName() + ", ");
     }
     if (items.size() > 1) {
       temp.append(temp + "and ");
     }
     temp.append(items.get(items.size() - 1).getName() + ".");
   } else {
     temp = new StringBuffer("This room contains no items that you can take.");
   }
   return temp.toString();
 }