コード例 #1
0
  Person(String name, double moneyz) {
    this.name = name;
    this.money = moneyz;
    roles.add(new ApartmentResidentRole(this, getName(), "Apartment Resident"));
    roles.add(new HousingResidentRole(this, getName(), "Housing Resident"));
    roles.add(new BankCustomerRole(this, getName(), "Bank Customer"));
    roles.add(new MarketCustomerRole(this, getName(), "Market Customer"));
    roles.add(
        new ChineseRestaurantCustomerRole(
            this,
            getName(),
            "Restaurant Customer",
            Phonebook.getPhonebook().getChineseRestaurant()));
    roles.add(new AmericanRestaurantCustomerRole(this, getName(), "Restaurant Customer"));
    nextTask = new Timer();
    atCityDestination = new Semaphore(0, true);
    setHunger(HungerLevel.full);
    hasFoodInFridge = false;

    // add restaurants to queue
    restaurantQueue = new ArrayList<String>();
    restaurantQueue.add("Chinese Restaurant");
    restaurantQueue.add("American Restaurant");
    restaurantQueue.add("Italian Restaurant");
    //	restaurantQueue.add("Chinese Restaurant");
    restaurantQueue.add("Seafood Restaurant");
  }
コード例 #2
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;
      }
    }
  }