Exemplo n.º 1
0
  protected void prepareForRestaurant() {

    String choice = restaurantQueue.get(0);
    for (int i = 0; i < restaurantQueue.size(); i++) {
      choice = restaurantQueue.get(i);
      if (choice.equals("Chinese Restaurant")
          && Phonebook.getPhonebook().getChineseRestaurant().isOpen()) {
        break;
      }
      if (choice.equals("Italian Restaurant")
          && Phonebook.getPhonebook().getItalianRestaurant().isOpen()) {
        break;
      }
      if (i == restaurantQueue.size()) print("Bummer, no restaurants open");
    }

    print("Going to become a customer at " + choice);

    restaurantQueue.remove(choice);
    restaurantQueue.add(choice);

    // Moving this choice to back of queue

    gui.walk = gui.decideForBus(choice);

    if (!gui.walk) {
      if (choice.equals("American Restaurant")) {
        print(
            "Destination bus Stop: "
                + Phonebook.getPhonebook()
                    .getAmericanRestaurant()
                    .getClosestBusStop()
                    .getBusStopNumber());
        goToBusStop(
            Phonebook.getPhonebook().getAmericanRestaurant().getClosestBusStop().getBusStopNumber(),
            Phonebook.getPhonebook().getAmericanRestaurant().location);
      }
      if (choice.equals("Chinese Restaurant")) {
        print(
            "Destination bus Stop: "
                + Phonebook.getPhonebook()
                    .getChineseRestaurant()
                    .getClosestBusStop()
                    .getBusStopNumber());
        goToBusStop(
            Phonebook.getPhonebook().getChineseRestaurant().getClosestBusStop().getBusStopNumber(),
            Phonebook.getPhonebook().getChineseRestaurant().location);
      }
      //			if (choice.contains("Seafood")){
      //				print("Destination bus Stop: " +
      // Phonebook.getPhonebook().getSeafoodRestaurant().getClosestBusStop().getBusStopNumber());
      //
      //	goToBusStop(Phonebook.getPhonebook().getSeafoodRestaurant().getClosestBusStop().getBusStopNumber());
      //			}
      if (choice.equals("Italian Restaurant")) {
        print(
            "Destination bus Stop: "
                + Phonebook.getPhonebook()
                    .getItalianRestaurant()
                    .getClosestBusStop()
                    .getBusStopNumber());
        goToBusStop(
            Phonebook.getPhonebook().getItalianRestaurant().getClosestBusStop().getBusStopNumber(),
            Phonebook.getPhonebook().getItalianRestaurant().location);
      }
      gui.command = Command.GoToRestaurant;
    }

    try {
      atCityDestination.acquire();
      //					if (!gui.walk){
      //						try {
      //							atCityDestination.acquire();
      //						} catch (InterruptedException e) {
      //							e.printStackTrace();
      //
      //						}
      //				}
    } catch (InterruptedException e) {
      e.printStackTrace();
    }

    for (Role cust1 : roles) {
      if (cust1 instanceof ChineseRestaurantCustomerRole) {
        ChineseRestaurantCustomerRole RCR = (ChineseRestaurantCustomerRole) cust1;
        if (Phonebook.getPhonebook().getChineseRestaurant().arrived(RCR)) {
          currentRoleName = "Chinese Restaurant Customer";
          cust1.setRoleActive();
          stateChanged();
        }
        return;
      }
      if (cust1 instanceof ItalianCustomerRole) {
        ItalianCustomerRole RCR = (ItalianCustomerRole) cust1;
        if (Phonebook.getPhonebook().getItalianRestaurant().arrived(RCR)) {
          currentRoleName = "Italian Restaurant Customer";
          cust1.setRoleActive();
          stateChanged();
        }
        return;
      }
      if (cust1 instanceof AmericanRestaurantCustomerRole) {
        AmericanRestaurantCustomerRole RCR = (AmericanRestaurantCustomerRole) cust1;
        if (Phonebook.getPhonebook().getAmericanRestaurant().customerArrived(RCR)) {
          currentRoleName = "American Restaurant Customer";
          cust1.setRoleActive();
          stateChanged();
        }
        return;
      }
    }
  }