Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

ResidentRole

Matthew Pohlmann edited this page Jan 1, 2014 · 1 revision

####Description All people in SimCity201 take on the Resident role when interacting in their own homes. Some residents are also Renters.

####Class Signature

public class ResidentRole extends Role implements Resident{}

####Data

ResidentState state;
Residence residence;
ResidentGui gui;
boolean isTest = false;
public enum ResidentState {doingNothing, hungry, eating, readyToSleep, sleeping, readyToWakeUp, payingRent, relaxing};

####Scheduler

switch (state) {
        case readyToSleep:
		goToSleep();
		return true;
	case hungry: 
	        if (residence.hasFood()) {
			pickAndEatFromFridge();
			return true;
		}
		else {
		        //GetFoodFromMarket?
			return false;
		}
	case relaxing:
		actionFinished();
		return true;
        default: 
		actionFinished();
		return false;
}

####Messages

public void msgStartEating() {
	state = ResidentState.hungry;
	stateChanged();
}

public void msgDoneEating() { //from animation
	state = ResidentState.doingNothing;
	stateChanged();
}

public void msgAnimationDone() {
        myPerson.animationRelease();
}

####Actions

void pickAndEatFromFridge() {
        goToFridge(); //gui
	state = ResidentState.eating;

        //pick random food
        residence.removeFood(randomFood);
	
        

}
private void goToSleep() {
		Do("Going to sleep");
		goToBed(); //animation go to bed
		state = ResidentState.sleeping;
		isActive = false;
		//timer/wait for wakeup
	}
void startInteraction(Intention intent) {
	switch (intent) {
		case ResidenceEat:
			this.msgStartEating();
			break;
		case ResidenceSleep:
			state = ResidentState.readyToSleep;
			stateChanged();
			break;
		case ResidenceRelax:
			state = ResidentState.relaxing;
			stateChanged();
			break;
		default:
			break;
	}
		
}
private void actionFinished() {
	state = ResidentState.doingNothing;
	isActive = false;
}

Wiki Home | Design Home

Clone this wiki locally