Pibd-22_Emelyanov_A.S._Airb.../DrawningEntities.java
2022-12-13 17:02:16 +04:00

58 lines
1.6 KiB
Java

import java.util.Random;
public class DrawningEntities <T extends EntityPlane, U extends IDrawningIlluminator>
{
public T[] _entities;
public U[] _illuminator;
int entitiesCount = 0;
int illumCount = 0;
String indx;
String indy;
public DrawningEntities(int countE,int countI){
_entities = (T[]) new EntityPlane[countE];
_illuminator = (U[]) new IDrawningIlluminator[countI];
}
public int Insert(T plane){
if(entitiesCount < _entities.length){
_entities[entitiesCount] = plane;
entitiesCount++;
return entitiesCount - 1;
}
return -1;
}
public int Insert(U illuminator){
if(illumCount < _illuminator.length){
_illuminator[illumCount] = illuminator;
illumCount++;
return illumCount - 1;
}
return -1;
}
public void SetIndexs(int ind1, int ind2)
{
indx=Integer.toString(ind1);
indy=Integer.toString(ind2);
}
public DrawningPlane CreatePlane(){
Random random = new Random();
int indEnt = 0;
int indIllum = 0;
if(entitiesCount - 1 != 0 & illumCount - 1 != 0){
indEnt = random.nextInt(0,entitiesCount - 1);
indIllum = random.nextInt(0, illumCount - 1);
}
T plane = (T)_entities[indEnt];
U illum = (U)_illuminator[indIllum];
SetIndexs(indEnt,indIllum);
if(plane instanceof EntityAirbus){
return new DrawningAirbus(plane,illum);
}
return new DrawningPlane(plane,illum);
}
}