I'm coding a rescue simulation program and while applying the required tests it keeps giving a failure saying that the number of occupants remaining in the building is not correctly calculated and I can't figure out why! below i provided the two methods that are supposed to give back the number of occupants. Thanks in advance!
public void treat(){
boolean f=false;
if(!f){
((Disaster)((Citizen)this.getTarget()).getDisaster()).setActive(false);
ResidentialBuilding r= (ResidentialBuilding)this.getTarget();
if(r.getOccupants().size()!=0){
for(int i=0;i<r.getOccupants().size();i++){
if(this.getPassengers().size()<=this.getMaxCapacity()){
f=true;
Citizen z=(Citizen)r.getOccupants().get(i);
if(z.getState()!=CitizenState.DECEASED){
r.getOccupants().remove(i);
this.getPassengers().add(z);
}
}
}
}
else{
this.setState(UnitState.IDLE);
this.jobsDone();
}
}
else
this.cycleStep();
}
public void cycleStep(){
if(super.getDistanceToBase()==0)
super.getWorldListener().assignAddress(this, 0, 0);
if(super.getTarget()!=null){
if(this.getLocation()== this.getTarget().getLocation()){
this.setDistanceToBase(this.getLocation().getX() + this.getLocation().getY());
}
else if(this.getDistanceToBase()<=0){
this.setDistanceToBase(0);
this.setLocation(new Address(0,0));
for (int i = 0; i < this.getPassengers().size(); i++) {
Citizen c = (Citizen)this.getPassengers().remove(i);
}
}
else{
this.setDistanceToBase(this.getDistanceToBase()-this.getStepsPerCycle());
}
}
}
Aucun commentaire:
Enregistrer un commentaire