40 lines
1.2 KiB
Java
40 lines
1.2 KiB
Java
import java.util.ArrayList;
|
|
import java.util.Random;
|
|
|
|
public class CreaterGeneric<T extends EntityWarship, U extends IDrawingObjectBlock> {
|
|
ArrayList<T> Warships;
|
|
ArrayList<U> Blocks;
|
|
int WarshipsCount=0;
|
|
int BlocksCount=0;
|
|
public CreaterGeneric(int warshipsCount,int blocksCount){
|
|
Warships=new ArrayList<>(warshipsCount);
|
|
Blocks=new ArrayList<>(blocksCount);
|
|
}
|
|
public int Add(T warship){
|
|
if(WarshipsCount<=Warships.size()){
|
|
Warships.add(warship);
|
|
WarshipsCount++;
|
|
return WarshipsCount-1;
|
|
}
|
|
return -1;
|
|
}
|
|
public int Add(U block){
|
|
if(BlocksCount<=Blocks.size()){
|
|
Blocks.add(block);
|
|
BlocksCount++;
|
|
return BlocksCount-1;
|
|
}
|
|
return -1;
|
|
}
|
|
public DrawingWarship NewWarshipCreating()
|
|
{
|
|
Random rand=new Random();
|
|
T warship = Warships.get(rand.nextInt(WarshipsCount));
|
|
U block = Blocks.get(rand.nextInt(BlocksCount));
|
|
if(warship instanceof EntityAdvancedWarship){
|
|
return new DrawingAdvancedWarship(warship,block);
|
|
}
|
|
return new DrawingWarship(warship,block);
|
|
}
|
|
}
|