コード例 #1
0
  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();
  }
コード例 #2
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);
 }
コード例 #3
0
 private void OrderIsReady(Order o) {
   print("OrderIsReady() called: " + o.order + " ready for table #: " + o.tableNum);
   DoGoToCookingArea();
   try {
     atDestination.acquire();
   } catch (InterruptedException e) {
     e.printStackTrace();
   }
   o.state = OrderState.GoingToPlating;
   cookGui.DoDisplayOrder(o.order + "(d)");
   cookGui.DoDisplayCookingOrders(getCookingOrders());
   DoGoToPlatingArea();
   try {
     atDestination.acquire();
   } catch (InterruptedException e) {
     e.printStackTrace();
   }
   cookGui.DoDisplayOrder("");
   WaiterAgent w = o.waiter;
   w.msgOrderReady(o.tableNum, o.order);
   orders.remove(o);
 }
コード例 #4
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 + "?");
 }
コード例 #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;
    }
  }
コード例 #7
0
 private void TellWaiterWeAreOut(Order o) {
   print("TellWaiterWeAreOut() called");
   WaiterAgent waiter = o.waiter;
   waiter.msgOutOfThisOrder(o.tableNum, o.order);
   orders.remove(o);
 }