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? }
protected void prepareForMarket() { print("Going to market as a customer"); if (home.type.equals("East Apartment")) gui.walk = gui.decideForBus("East Market"); else gui.walk = gui.decideForBus("West Market"); if (!gui.walk) { print( "Destination bus Stop: " + Phonebook.getPhonebook().getEastBank().getClosestBusStop().getBusStopNumber()); 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); } gui.command = Command.GoToMarket; } if (gui.walk) { try { atCityDestination.acquire(); } catch (InterruptedException e) { e.printStackTrace(); } } // Checking if have enough money for car if (accountBalance >= (carCost + 100)) { if (carStatus == CarState.noCar) { carStatus = CarState.wantsCar; } } if (hasFoodInFridge == false) { // choosing random item to buy from market for (Role cust1 : roles) { if (cust1 instanceof MarketCustomerRole) { MarketCustomerRole MCR = (MarketCustomerRole) cust1; MCR.setItem(""); cust1.setRoleActive(); if (home.type.equals("East Apartment")) Phonebook.getPhonebook().getEastMarket().arrived(MCR); else Phonebook.getPhonebook().getWestMarket().arrived(MCR); currentRoleName = "Market Customer"; stateChanged(); return; } } } else if (carStatus == CarState.wantsCar) { for (Role cust1 : roles) { if (cust1 instanceof MarketCustomerRole) { MarketCustomerRole MCR = (MarketCustomerRole) cust1; MCR.setItem("Car"); cust1.setRoleActive(); Phonebook.getPhonebook().getEastMarket().arrived(MCR); currentRoleName = "Market Customer"; stateChanged(); return; } } } }
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; } } }
protected void prepareForBank() { if (home.type.equals("East Apartment")) gui.walk = gui.decideForBus("East Bank"); else gui.walk = gui.decideForBus("West Bank"); if (!gui.walk) { print( "Destination bus Stop: " + Phonebook.getPhonebook().getEastBank().getClosestBusStop().getBusStopNumber()); if (home.type.equals("East Apartment")) { goToBusStop( Phonebook.getPhonebook().getEastBank().getClosestBusStop().getBusStopNumber(), Phonebook.getPhonebook().getEastBank().location); } else { goToBusStop( Phonebook.getPhonebook().getWestBank().getClosestBusStop().getBusStopNumber(), Phonebook.getPhonebook().getWestBank().location); } gui.command = Command.GoToBank; } try { atCityDestination.acquire(); if (!gui.walk) { atCityDestination.acquire(); } } catch (InterruptedException e) { e.printStackTrace(); } for (Role cust1 : roles) { if (cust1 instanceof BankCustomerRole) { BankCustomerRole BCR = (BankCustomerRole) cust1; BankCustomerGui bg = new BankCustomerGui(BCR); BCR.setGui(bg); if (this instanceof Crook) { print("Time to rob da bank fools!"); currentRoleName = "Bank Robber"; BCR.setDesire("robBank"); BCR.state = CustomerState.ready; } else { Do("Becoming Bank Customer"); currentRoleName = "Bank Customer"; if (money <= moneyMinThreshold) desiredCash = 100; else if (money >= moneyMaxThreshold) depositAmount = money - moneyMaxThreshold + 100; if (accountNum != 0) { if (money <= moneyMinThreshold) { BCR.setDesire("withdraw"); } if (money >= moneyMaxThreshold) { BCR.setDesire("deposit"); } } } cust1.setRoleActive(); if (home.type.equals("East Apartment")) Phonebook.getPhonebook().getEastBank().msgCustomerArrived(BCR); else Phonebook.getPhonebook().getWestBank().msgCustomerArrived(BCR); stateChanged(); return; } } }