57 lines
1.5 KiB
Java
57 lines
1.5 KiB
Java
import java.util.Random;
|
|
|
|
public class DrawningEntities <T extends EntityBoat, U extends IDrawningOars>
|
|
{
|
|
public T[] _entities;
|
|
public U[] _oars;
|
|
int entitiesCount = 0;
|
|
int oarsCount = 0;
|
|
String indx;
|
|
String indy;
|
|
|
|
public DrawningEntities(int countE,int countI){
|
|
_entities = (T[]) new EntityBoat[countE];
|
|
_oars = (U[]) new IDrawningOars[countI];
|
|
}
|
|
|
|
public int Insert(T boat){
|
|
if(entitiesCount < _entities.length){
|
|
_entities[entitiesCount] = boat;
|
|
entitiesCount++;
|
|
return entitiesCount - 1;
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
public int Insert(U oars){
|
|
if(oarsCount < _oars.length){
|
|
_oars[oarsCount] = oars;
|
|
oarsCount++;
|
|
return oarsCount - 1;
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
public void SetIndexs(int ind1, int ind2)
|
|
{
|
|
indx=Integer.toString(ind1);
|
|
indy=Integer.toString(ind2);
|
|
}
|
|
|
|
public DrawningBoat CreateBoat(){
|
|
Random random = new Random();
|
|
int indEnt = 0;
|
|
int indOar = 0;
|
|
if(entitiesCount - 1 != 0 & oarsCount - 1 != 0){
|
|
indEnt = random.nextInt(0,entitiesCount - 1);
|
|
indOar = random.nextInt(0, oarsCount - 1);
|
|
}
|
|
T boat = (T)_entities[indEnt];
|
|
U oar = (U)_oars[indOar];
|
|
SetIndexs(indEnt,indOar);
|
|
if(boat instanceof EntityCatamaran){
|
|
return new DrawningCatamaran(boat,oar);
|
|
}
|
|
return new DrawningBoat(boat,oar);
|
|
}
|
|
} |