2022-10-22 01:15:02 +04:00
|
|
|
import java.util.Random;
|
|
|
|
|
|
|
|
public class EntityWithExtraCreator <T extends EntityLocomotive, U extends IDrawningExtra> {
|
2022-10-22 16:12:48 +04:00
|
|
|
private EntityLocomotive[] entityArr;
|
|
|
|
private IDrawningExtra[] extraArr;
|
2022-10-22 01:15:02 +04:00
|
|
|
|
|
|
|
int entitiesCount = 0;
|
|
|
|
int extraCount = 0;
|
|
|
|
|
|
|
|
public EntityWithExtraCreator(int countEntities, int countExtra) {
|
2022-10-22 16:12:48 +04:00
|
|
|
entityArr = new EntityLocomotive[countEntities];
|
|
|
|
extraArr = new IDrawningExtra[countExtra];
|
2022-10-22 01:15:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public int Insert(T entityLocomotive) {
|
|
|
|
if(entitiesCount < entityArr.length) {
|
|
|
|
entityArr[entitiesCount] = entityLocomotive;
|
|
|
|
entitiesCount++;
|
|
|
|
return entitiesCount - 1;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int Insert (U extra) {
|
|
|
|
if(extraCount < extraArr.length) {
|
|
|
|
extraArr[extraCount] = extra;
|
|
|
|
extraCount++;
|
|
|
|
return extraCount - 1;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
public DrawningLocomotive getEntityWithExtra() {
|
|
|
|
Random random = new Random();
|
|
|
|
int getEntityRandomIndex = random.nextInt(entityArr.length);
|
|
|
|
int getExtraRandomIndex = random.nextInt(extraArr.length);
|
|
|
|
|
2022-10-22 16:12:48 +04:00
|
|
|
EntityLocomotive locomotive = entityArr[getEntityRandomIndex];
|
|
|
|
IDrawningExtra extra = extraArr[getExtraRandomIndex];
|
2022-10-22 01:15:02 +04:00
|
|
|
|
|
|
|
if (locomotive instanceof EntityWarmlyLocomotive) {
|
|
|
|
return new DrawningWarmlyLocomotive(locomotive, extra);
|
|
|
|
}
|
|
|
|
return new DrawningLocomotive(locomotive, extra);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|