Hajj-simulation/src/CivilVehicle.java

57 lines
1.3 KiB
Java
Raw Normal View History

import java.util.Date;
public abstract class CivilVehicle extends Vehicle implements Breakable {
private boolean broken;
private Accident currentAccident;
private Date breakDownTime;
public CivilVehicle(double vehicleSize) {
super(vehicleSize);
}
@Override
public boolean isBroken() {
return broken;
}
@Override
public Accident collide(Breakable car, Date time, Street location) {
if (currentAccident == null) {
Breakable[] cars = new Breakable[2];
cars[0] = this;
cars[1] = car;
Accident accident = new Accident(time, cars, location);
this.currentAccident = accident;
if (car instanceof CivilVehicle)
((CivilVehicle)car).setCurrentAccident(accident);
return accident;
}
return null;
}
@Override
public void _break(Date time) {
broken = true;
this.breakDownTime = time;
}
@Override
public void fix() {
broken = false;
this.currentAccident = null;
}
public Date getBreakDownTime() {
return breakDownTime;
}
public Accident getCurrentAccident() {
return currentAccident;
}
public void setCurrentAccident(Accident accident){
if (accident != null) this.currentAccident = accident;
}
}