コード例 #1
0
  private void leaveRestaurant() {
    check = null;
    log("I'm leaving! Goodbye!");
    customerGui.DoExitRestaurant();

    person.setGuiVisible();
    person.setRoleInactive(this);
  }
コード例 #2
0
  private void readyToOrder() {
    customerGui.clearOrder();

    timer.schedule(
        new TimerTask() {
          public void run() {
            log("I'm ready to order!");
            callWaiter();
          }
        },
        3000);
  }
コード例 #3
0
  private void orderFood() {
    if (menu.getChoice(choice).price < money) {
      log("I would like an order of " + choice + " please!");

      customerGui.orderedFood(choice);
      log(choice + " please!");

      waiter.msgHereIsMyChoice(this, choice);
    } else {
      for (int i = 0; i < menu.getMenuSize(); i++) { // Try to find a choice the customer can afford
        if (menu.getChoice(i).price < money) {
          choice = menu.getChoice(i).type;

          log("I would like an order of " + choice + " please!");

          customerGui.orderedFood(choice);
          log(choice + " please!");

          waiter.msgHereIsMyChoice(this, choice);
          return;
        }
      }
      if (name.equals("flake")) { // This customer will buy food he/she can't afford
        log("I would like an order of " + choice + " please!");

        customerGui.orderedFood(choice);
        log(choice + " please!");

        waiter.msgHereIsMyChoice(this, choice);
      } else {
        log("Everything is too expensive, I'm going to leave.");

        customerGui.doneEating();
        waiter.msgImFinished(this);
        event = AgentEvent.leaving;
      }
    }
  }
コード例 #4
0
  private void payBill() {
    waiter.msgImFinished(this);

    customerGui.DoGoToCashier();

    try {
      atDestination.acquire();
    } catch (InterruptedException e) {
      e.printStackTrace();
    }

    if (money > check.amount) {
      log("Here is my payment of $" + money + ".");
      check.cashier.msgPayBill(check, money);
      money = 0.0;
    } else {
      check.cashier.msgPayBill(check, money);
      log("This is all I have. Take $" + money + ".");
      money = 0;
    }
  }
コード例 #5
0
 private void eatFood() {
   log("Eating Food");
   customerGui.startedEating(choice);
   // This next complicated line creates and starts a timer thread.
   // We schedule a deadline of getHungerLevel()*1000 milliseconds.
   // When that time elapses, it will call back to the run routine
   // located in the anonymous class created right there inline:
   // TimerTask is an interface that we implement right there inline.
   // Since Java does not all us to pass functions, only objects.
   // So, we use Java syntactic mechanism to create an
   // anonymous inner class that has the public method run() in it.
   timer.schedule(
       new TimerTask() {
         public void run() {
           log("Done eating!");
           event = AgentEvent.doneEating;
           GuiDoneEating();
           // isHungry = false;
           person.stateChanged();
         }
       },
       hungerLevel * 1000); // how long to wait before running task
 }
コード例 #6
0
 public void setGuiActive() {
   customerGui.setPresent(true);
   customerGui.setHungry();
 }
コード例 #7
0
 private void impatientLeaveRestaurant() {
   log("I'm leaving! Goodbye!");
   host.msgImLeaving(this);
   customerGui.DoExitRestaurant();
 }
コード例 #8
0
 private void GuiDoneEating() {
   customerGui.doneEating();
 }
コード例 #9
0
 private void callWaiter() {
   waiter.msgImReadyToOrder(this);
   customerGui.wantToOrder();
 }
コード例 #10
0
 private void sitDown() {
   log("Being seated. Going to table");
   customerGui.DoGoToSeat();
 }
コード例 #11
0
 private void goToWaitingSpot() {
   customerGui.DoGoToSpot(waitingSpot);
   goingInside = false;
 }