コード例 #1
0
 private void SitDown() {
   Do("Being seated. Going to table");
   for (Table t : host.tables) {
     if (t.getOccupant() == this) {
       this.table = t.num;
       customerGui.DoGoToSeat(t.num);
       break;
     }
   }
   waiter.msgImReadyToOrder(this);
 }
コード例 #2
0
 private void EatFood() {
   customerGui.setText(choice);
   Do("Eating Food");
   timer.schedule(
       new TimerTask() {
         public void run() {
           print("Done eating");
           event = AgentEvent.doneEating;
           stateChanged();
         }
       },
       getHungerLevel() * 1000);
 }
コード例 #3
0
 private void OrderFood() {
   choice = name.toLowerCase();
   int count = 0;
   while (!menu.menuList.contains(choice)
       || unavailableFood.contains(choice)
       || (menu.menuItems.get(choice) > wallet.getAmt() && !name.equalsIgnoreCase("bad"))) {
     if (count == menu.menuList.size()) {
       state = AgentState.Leaving;
       eatingSuccess = false;
       LeaveRestaurant();
       return;
     }
     //	Random rand = new Random(System.currentTimeMillis());
     //	int det = Math.abs(rand.nextInt()%(menu.menuList.size()));
     choice = menu.menuList.get(count++);
     Do("" + choice);
   }
   waiter.msgHereIsMyChoice(this, choice);
   customerGui.setText(choice + "?");
 }
コード例 #4
0
 private void LeaveRestaurant() {
   Do("Leaving.");
   customerGui.setText("");
   customerGui.DoExitRestaurant();
 }
コード例 #5
0
 private void LeaveTableToGoPay() {
   Do("Going to pay");
   waiter.msgLeavingTable(this);
   customerGui.setText("check");
   customerGui.DoGoToCashier();
 }
コード例 #6
0
  /** Scheduler. Determine what action is called for, and do it. */
  protected boolean pickAndExecuteAnAction() {
    //	CustomerAgent is a finite state machine
    try {
      if (state == AgentState.DoingNothing && event == AgentEvent.gotHungry) {
        if (host.isFull() && name.equalsIgnoreCase("wait")) {
          customerGui.setEnabled();
          customerGui.DoExitRestaurant();
          return true;
        }
        state = AgentState.Waiting;
        GoToRestaurant();
        return true;
      }
      if (state == AgentState.Waiting && event == AgentEvent.followHost) {
        state = AgentState.BeingSeated;
        SitDown();
        return true;
      }
      if (state == AgentState.BeingSeated && event == AgentEvent.seated) {
        state = AgentState.Seated;

        return true;
      }
      if (state == AgentState.Seated && event == AgentEvent.orderFood) {
        state = AgentState.Ordered;
        OrderFood();
        return true;
      }
      if (state == AgentState.Ordered && event == AgentEvent.orderTaken) {
        state = AgentState.WaitingForOrder;
        return true;
      }
      if (state == AgentState.WaitingForOrder && event == AgentEvent.foodArrived) {
        state = AgentState.Eating;
        EatFood();
        return true;
      }

      if (state == AgentState.Eating && event == AgentEvent.doneEating) {
        state = AgentState.WaitingForCheck;
        customerGui.setText("");
        waiter.msgDoneEating(this);
        return true;
      }
      if (state == AgentState.WaitingForCheck && event == AgentEvent.rcvdCheck) {
        state = AgentState.Paying;
        LeaveTableToGoPay();
        return true;
      }
      if (state == AgentState.Paying && event == AgentEvent.arrivedAtCashier) {
        host.cashier.msgHereIsMoney(this, wallet.getAmt());
        return true;
      }
      if (state == AgentState.Paying && event == AgentEvent.doDishes) {
        DoDishes();
        return true;
      }
      if (state == AgentState.Paying && event == AgentEvent.donePaying) {
        state = AgentState.Leaving;
        eatingSuccess = true;
        LeaveRestaurant();
        return true;
      }
      if (state == AgentState.Leaving && event == AgentEvent.doneLeaving) {
        state = AgentState.DoingNothing;
        //				person.msgDoneEating(eatingSuccess, wallet.getAmt()); // COMMENT THIS OUT IF THERE
        // AREN'T REAL PEOPLE IN THE RESTAURANT
        waiter.msgDoneLeaving(this);
        return true;
      }
      return false;
    } catch (ConcurrentModificationException e) {
      return false;
    }
  }