我正在编写一个救援模拟程序,并且在应用所需的测试时,它一直失败,提示建筑物中剩余的居住人数没有正确计算,我不知道为什么! 在下面,我提供了两种应该返还乘员人数的方法。 预先感谢!
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());
}
}
}