44 lines
1.3 KiB
Java
44 lines
1.3 KiB
Java
import java.util.Random;
|
|
|
|
public class EntityWithDecks<T extends EntityShip, U extends IDrawingDecks> {
|
|
static Random rnd = new Random();
|
|
private final Object[] entities;
|
|
public int entitiesCount = 0;
|
|
private final Object[] decks;
|
|
public int decksCount = 0;
|
|
|
|
public EntityWithDecks(int count) {
|
|
entities = new Object[count];
|
|
decks = new Object[count];
|
|
}
|
|
|
|
public boolean add(EntityShip entity) {
|
|
if (entitiesCount >= entities.length) {
|
|
return false;
|
|
}
|
|
entities[entitiesCount++] = entity;
|
|
return true;
|
|
}
|
|
|
|
public boolean add(IDrawingDecks deck) {
|
|
if (decksCount >= decks.length) {
|
|
return false;
|
|
}
|
|
decks[decksCount++] = deck;
|
|
return true;
|
|
}
|
|
|
|
public IDrawingObject constructShip() {
|
|
if (entitiesCount == 0 || decksCount == 0) {
|
|
return null;
|
|
}
|
|
EntityShip entity = (EntityShip) entities[rnd.nextInt(0, entitiesCount)];
|
|
IDrawingDecks deck = (IDrawingDecks) decks[rnd.nextInt(0, decksCount)];
|
|
|
|
if (entity instanceof EntityMotorShip advancedEntity) {
|
|
return new DrawingObjectShip(new DrawingMotorShip(advancedEntity, deck));
|
|
}
|
|
return new DrawingObjectShip(new DrawingShip(entity, deck));
|
|
}
|
|
}
|