예제 #1
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?
  }
예제 #2
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();
    }
  }