110 lines
3.4 KiB
Java
110 lines
3.4 KiB
Java
package items;
|
|
|
|
import exceptions.CannotBeHidedException;
|
|
import exceptions.VehicleDriverException;
|
|
import exceptions.VehicleIsBrokenException;
|
|
|
|
import items.enums.VehicleType;
|
|
import persons.Person;
|
|
|
|
import items.interfaces.CanBeInvestigated;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
public class Vehicle extends Item implements CanBeInvestigated {
|
|
private final VehicleType type;
|
|
private Person driver;
|
|
private String destination;
|
|
private boolean isMoving;
|
|
private ArrayList<Person> passengers;
|
|
private ArrayList<Item> trunk;
|
|
private int durability;
|
|
private final int speed;
|
|
|
|
// suspicious stuff
|
|
boolean isSuspicious = false;
|
|
|
|
public Vehicle(
|
|
Person owner, Double weight, Boolean isBroken,
|
|
VehicleType type, Person driver, String destination,
|
|
boolean isMoving, int durability, int speed
|
|
) {
|
|
super(owner, weight, isBroken);
|
|
this.type = type;
|
|
this.driver = driver;
|
|
this.destination = destination;
|
|
this.isMoving = isMoving;
|
|
this.durability = durability;
|
|
this.speed = speed;
|
|
}
|
|
|
|
public Vehicle(Person owner, Boolean isBroken, VehicleType type, Person driver, String destination) {
|
|
super(owner, type.getWeight(), isBroken);
|
|
this.type = type;
|
|
this.driver = driver;
|
|
this.destination = destination;
|
|
this.isMoving = false;
|
|
this.durability = type.getDurability();
|
|
this.speed = type.getSpeed();
|
|
|
|
}
|
|
|
|
// destination
|
|
public boolean move(String destination) throws VehicleIsBrokenException {
|
|
if (this.getIsBroken()) {
|
|
this.destination = destination;
|
|
return true;
|
|
} else {
|
|
throw new VehicleIsBrokenException("Машина " + this.getOwner() + " под управлением " + this.driver + " сломана");
|
|
}
|
|
}
|
|
|
|
public String getDestination() {return this.destination;}
|
|
|
|
// info
|
|
public VehicleType getType() {return this.type;}
|
|
public boolean getIsMoving() {return this.isMoving;}
|
|
public int getSpeed() {return this.speed;}
|
|
|
|
// passengers
|
|
public Person[] getPassengers() {
|
|
return this.passengers.toArray(new Person[0]);
|
|
}
|
|
public void setPassengers(ArrayList<Person> p) {this.passengers = p;}
|
|
public void setPassengers(Person p) {this.passengers.add(p);}
|
|
|
|
// trunk
|
|
public Item[] getTrunk() {return this.trunk.toArray(new Item[0]);}
|
|
public void setTrunk(ArrayList<Item> t) {this.trunk = t;}
|
|
public void setTrunk(Item t) {this.trunk.add(t);}
|
|
|
|
// "I drive" - Ryan Gosling
|
|
public Person getDriver() {return this.driver;}
|
|
public void setDriver(Person driver) throws VehicleDriverException {
|
|
if (passengers.contains(driver)) {
|
|
this.driver = driver;
|
|
} else {
|
|
throw new VehicleDriverException(driver.getName() + " не в машине либо уже является водителем");
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void setIsLost(boolean isLost) throws CannotBeHidedException {
|
|
throw new CannotBeHidedException("Машина не может быть спрятана");
|
|
}
|
|
|
|
// damage
|
|
@Override
|
|
public void doBreak() {
|
|
if (this.durability > 0) {
|
|
this.durability--;
|
|
} else {
|
|
this.isMoving = false;
|
|
super.doBreak();
|
|
}
|
|
}
|
|
|
|
public int getDurability() {return this.durability;}
|
|
|
|
}
|