Exemplo n.º 1
0
  protected void startHungerTimer() {
    setHunger(HungerLevel.moderate);

    // After arrives home
    hungerTimer.schedule(
        new TimerTask() {
          public void run() {
            print("I'm hungry...time to eat!");
            setHunger(HungerLevel.hungry);
            stateChanged();
          }
        },
        (12000)); // Check this math please?
  }
Exemplo n.º 2
0
  protected void goToSleep() {

    gui.walk = gui.decideForBus("Home");
    if (!gui.walk) {
      if (home.type.equals("East Apartment")) {
        goToBusStop(
            Phonebook.getPhonebook().getEastMarket().getClosestBusStop().getBusStopNumber(),
            Phonebook.getPhonebook().getEastMarket().location);
      } else {
        goToBusStop(
            Phonebook.getPhonebook().getWestMarket().getClosestBusStop().getBusStopNumber(),
            Phonebook.getPhonebook().getWestMarket().location);
      }
      //			if (home.type.equals("East Apartment")){
      //				gui.doGoToBus(Phonebook.getPhonebook().getEastMarket()//.getClosestStop().getX(),
      //						Phonebook.getPhonebook().getEastMarket().getClosestStop().getY());
      //			}
      //			else {
      //				gui.doGoToBus(Phonebook.getPhonebook().getWestMarket().getClosestStop().getX(),
      //						Phonebook.getPhonebook().getWestMarket().getClosestStop().getY());
      //			}
      gui.command = Command.GoHome;
    }

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

    // person is part of an apartment
    if (getHousing().type.toLowerCase().contains("apartment")) {
      if (getHousing().type.toLowerCase().contains("east")) {
        for (Role cust1 : roles) {
          if (cust1 instanceof ApartmentResidentRole) {
            ApartmentResidentRole ARR = (ApartmentResidentRole) cust1;
            if (Phonebook.getPhonebook().getEastApartment().arrived(ARR)) {
              currentRoleName = "EAST Apartment Resident";
              ARR.setRoleActive();
              stateChanged();
            }
            return;
          }
        }
      } else if (getHousing().type.toLowerCase().contains("west")) {
        for (Role cust1 : roles) {
          if (cust1 instanceof ApartmentResidentRole) {
            ApartmentResidentRole ARR = (ApartmentResidentRole) cust1;
            if (Phonebook.getPhonebook().getWestApartment().arrived(ARR)) {
              currentRoleName = "WEST Apartment Resident";
              cust1.setRoleActive();
              stateChanged();
            }
            return;
          }
        }
      }

      // person is NOT part of an apartment
    } else if (getHousing().type.toLowerCase().contains("Mansion")) { // CHANGE BACK TO MANSION
      for (Role cust1 : roles) {
        if (cust1 instanceof HousingResidentRole) {
          HousingResidentRole HRR = (HousingResidentRole) cust1;
          if (getHousing().arrived(HRR)) {
            currentRoleName = "Housing Resident";
            cust1.setRoleActive();
            stateChanged();
          }
          return;
        }
      }
    }

    // After arrives home
    alarmClock.schedule(
        new TimerTask() {
          public void run() {
            stateChanged();
          }
        },
        (((24 - TimeManager.getTimeManager().getTime().dayHour) + 8)
            * 500)); // Check this math please?
  }
Exemplo n.º 3
0
  // Actions
  protected void eatAtHome() {
    currentRoleName = "Housing Resident";
    int timeConversion = 60 * TimeManager.getSpeedOfTime();
    print("Going to eat at home");
    // if(getGui().getxPos() != getGui().getxHome() || getGui().getyPos() != getGui().getxHome()) {
    getGui().DoGoHome();
    try {
      this.atCityDestination.acquire();
    } catch (InterruptedException e) {
      e.printStackTrace();
      //
    }
    // }

    // person is part of an apartment
    if (getHousing().type.toLowerCase().contains("apartment")) {
      if (getHousing().type.toLowerCase().contains("east")) {
        for (Role cust1 : roles) {
          if (cust1 instanceof ApartmentResidentRole) {
            ApartmentResidentRole ARR = (ApartmentResidentRole) cust1;
            if (Phonebook.getPhonebook().getEastApartment().arrived(ARR)) {
              currentRoleName = "EAST Apartment Resident";
              ARR.setRoleActive();
              stateChanged();
            }
            return;
          }
        }
      } else if (getHousing().type.toLowerCase().contains("west")) {
        for (Role cust1 : roles) {
          if (cust1 instanceof ApartmentResidentRole) {
            ApartmentResidentRole ARR = (ApartmentResidentRole) cust1;
            if (Phonebook.getPhonebook().getWestApartment().arrived(ARR)) {
              currentRoleName = "WEST Apartment Resident";
              cust1.setRoleActive();
              stateChanged();
            }
            return;
          }
        }
      }

      // person is NOT part of an apartment
    } else if (getHousing().type.toLowerCase().contains("Mansion")) { // CHANGE BACK TO MANSION
      for (Role cust1 : roles) {
        if (cust1 instanceof HousingResidentRole) {
          HousingResidentRole HRR = (HousingResidentRole) cust1;
          if (getHousing().arrived(HRR)) {
            currentRoleName = "Housing Resident";
            cust1.setRoleActive();
            stateChanged();
          }
          return;
        }
      }
    }

    nextTask.schedule(
        new TimerTask() {
          public void run() {
            eating.release();
            hasFoodInFridge = false;
            print("Finished eating at home");
            hunger = HungerLevel.full;
          }
        },
        eatTime * timeConversion);
    try {
      eating.acquire();
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
  }