public void setQuantity(String name, int num) {
   for (Food food : foods) {
     if (food.choice.equals(name)) {
       food.amount = num;
     }
   }
 }
  public void msgNewOrder(WaiterAgent w, int tableNum, String order) {
    print("msgNewOrder() from Waiter " + w.getName());
    long timeFinish = -1;
    if (findFood(order).amount > 0) {
      timeFinish =
          (System.currentTimeMillis() + (long) ((menu.menuItems.get(order)) * Constants.SECOND));
      int previousInventoryAmount = inventory.get(order);
      inventory.put(order, previousInventoryAmount - 1);
      print("Number of items of type " + order + " left: " + inventory.get(order));

      Order incomingOrder = new Order(w, tableNum, order, timeFinish);
      orders.add(incomingOrder);
      Food f = findFood(order);
      f.amount--;
      if (f.amount <= f.low) {
        marketOrders.add(new MarketOrder(f.choice, f.capacity - f.amount));
        f.ordered = true;
      }
    } else {
      Order incomingOrder = new Order(w, tableNum, order, timeFinish);
      incomingOrder.state = OrderState.UnableToBeSupplied;
      menu.menuList.remove(order);
      orders.add(incomingOrder);
      Food f = findFood(order);
      marketOrders.add(new MarketOrder(f.choice, f.capacity - f.amount));
    }
    stateChanged();
  }
예제 #3
0
파일: Blob.java 프로젝트: peter9207/petGame
 /**
  * eat food decrease hunger meter and increase in satiability
  *
  * @param food
  */
 public void eat(Food food) {
   // eat Meal or Snack; modifies happinessMeter and hungerMeter
   this.happinessMeter += food.getTastiness();
   this.hungerMeter -= food.getSatiability();
   this.size += food.getFat();
   if (this.hungerMeter <= 0) {
     this.hungerMeter = 0;
   }
 }
 /*
 Order(Cook cook, Food f, int amount) {
 	c = cook;
 	food = f;
 	f.orderamt = amount;
 	s = OrderState.pending;
 }*/
 Order(ItalianCook cook, Food f, int amount, int left) {
   c = cook;
   food = f;
   f.orderamt = amount;
   leftover = left;
   s = OrderState.pending;
 }
 public void msgHereIsOrder(String choice, int amount, int id) {
   print("Received a delivery of " + amount + " " + choice + "'s from the market!");
   for (int i = 0; i < marketOrders.size(); i++) {
     MarketOrder mo = marketOrders.get(i);
     if (mo.id == id && mo.amount == amount) {
       Food f = findFood(mo.food);
       f.amount = amount;
       print("removing a market order whee");
       marketOrders.remove(mo);
     } else if (mo.food == choice && mo.amount != 0) {
       Food f = findFood(mo.food);
       f.amount = amount + mo.amount;
       mo.amount -= amount;
     }
   }
 }
예제 #6
0
  public void update() {
    // System.out.println("updating creature");

    // nothing to update if dead
    if (!isAlive()) {
      return;
    }

    // mark as dead if health <= 0
    if (health <= 0) {
      alive = false;
      return;
    }

    if (mateWait > 0) {
      mateWait--;
    }

    Creature child;
    Food food;
    LinkedList<Food> flist = world.getFoodList();

    interactList = getCreaturesInRange(interactionRange);

    double healAmt;

    // heal injuries, rate proportional to energy
    //        if (health < maxHealth) {
    //            healAmt = baseHealRate * (energy / baseEnergy);
    //            health += (healAmt > maxHealRate) ? maxHealRate : healAmt;
    //            // cap max health
    //            if (health > maxHealth) {
    //                health = maxHealth;
    //            }
    //        }

    age++;

    controller.update();
    doAction(controller.chooseAction());

    // System.out.println("checking for food to eat...");
    food = (Food) findNearestInList(flist);
    if (distTo(food) <= 2) {
      addEnergy(food.bite());
    } else {
      subEnergy(energyLossRate);
    }

    if (energy <= 0) {
      subHealth(starveRate);
    }

    // mate if energy above threshold
    if (energy > mateThreshold) {
      for (Creature c : interactList) {
        if (isWillingToMateWith(c)) {
          child = mateWith(c);
          if (child != null) {
            world.insertChild(child);
          }
          break;
        }
      }
    }

    if (age > oldAge) {
      subHealth((age - oldAge) * world.r.nextDouble());
    }
    // System.out.println("creature finished updating");
  }
 public String toString() {
   return food.toString();
 }