49 lines
1.4 KiB
Java
49 lines
1.4 KiB
Java
import java.util.ArrayList;
|
|
import java.util.Random;
|
|
|
|
public class EntityWithRollers<T extends EntityTracktor, U extends IDrawningRollers> {
|
|
static Random rnd = new Random();
|
|
private ArrayList<T> entities;
|
|
private ArrayList<U> rollers;
|
|
|
|
public int maxEntitiesCount = 0;
|
|
public int maxRollersCount = 0;
|
|
|
|
public EntityWithRollers(int count) {
|
|
entities = new ArrayList<T>();
|
|
rollers = new ArrayList<U>();
|
|
maxEntitiesCount = count;
|
|
maxRollersCount = count;
|
|
}
|
|
|
|
public boolean add(T entity) {
|
|
if (entities.size() >= maxEntitiesCount){
|
|
return false;
|
|
}
|
|
entities.add(entity);
|
|
return true;
|
|
}
|
|
|
|
public boolean add(U roller) {
|
|
if (rollers.size() >= maxRollersCount){
|
|
return false;
|
|
}
|
|
rollers.add(roller);
|
|
return true;
|
|
}
|
|
|
|
public IDrawningObject constructTracktor() {
|
|
if (entities.size() == 0 || rollers.size() == 0) {
|
|
return null;
|
|
}
|
|
|
|
EntityTracktor entity = (EntityTracktor) entities.get(rnd.nextInt(0, entities.size()));
|
|
IDrawningRollers roller = (IDrawningRollers) rollers.get(rnd.nextInt(0, rollers.size()));
|
|
|
|
if (entity instanceof EntityTrackedVehicle advancedEntity) {
|
|
return new DrawningObjectExcavator(new DrawningTrackedVehicle(advancedEntity, roller));
|
|
}
|
|
return new DrawningObjectExcavator(new DrawningTracktor(entity, roller));
|
|
}
|
|
}
|