58 lines
1.5 KiB
Java
58 lines
1.5 KiB
Java
|
import java.util.Random;
|
||
|
|
||
|
public class DrawingEntities <T extends EntityShip,U extends IAdditionalDrawingObject>{
|
||
|
public T[] _entities;
|
||
|
public U[] _decks;
|
||
|
int entitiesCount = 0;
|
||
|
int decksCount = 0;
|
||
|
String indx;
|
||
|
String indy;
|
||
|
public DrawingEntities(int countE,int countD)
|
||
|
{
|
||
|
_entities = (T[]) new EntityShip[countE];
|
||
|
_decks = (U[]) new IAdditionalDrawingObject[countD];
|
||
|
}
|
||
|
public int Insert(T ship)
|
||
|
{
|
||
|
if(entitiesCount<_entities.length){
|
||
|
_entities[entitiesCount] = ship;
|
||
|
entitiesCount++;
|
||
|
return entitiesCount-1;
|
||
|
}
|
||
|
return -1;
|
||
|
}
|
||
|
public int Insert(U deck)
|
||
|
{
|
||
|
if(decksCount<_decks.length){
|
||
|
_decks[decksCount] = deck;
|
||
|
decksCount++;
|
||
|
return decksCount-1;
|
||
|
}
|
||
|
return -1;
|
||
|
}
|
||
|
public void SetIndexs(int ind1, int ind2)
|
||
|
{
|
||
|
indx=Integer.toString(ind1);
|
||
|
indy=Integer.toString(ind2);
|
||
|
}
|
||
|
public DrawingShip CreateShip()
|
||
|
{
|
||
|
Random rnd = new Random();
|
||
|
int indEnt=0;
|
||
|
int indDeck=0;
|
||
|
if(entitiesCount-1!=0 & decksCount-1!=0)
|
||
|
{
|
||
|
indDeck=rnd.nextInt(0,decksCount-1);
|
||
|
indEnt=rnd.nextInt(0,entitiesCount-1);
|
||
|
}
|
||
|
T ship=(T)_entities[indEnt];
|
||
|
U deck=(U)_decks[indDeck];
|
||
|
SetIndexs(indEnt,indDeck);
|
||
|
if(ship instanceof EntityContainerShip)
|
||
|
{
|
||
|
return new DrawingContainerShip(ship,deck);
|
||
|
}
|
||
|
return new DrawingShip(ship,deck);
|
||
|
}
|
||
|
}
|