42 lines
1.2 KiB
Java
42 lines
1.2 KiB
Java
import java.io.Console;
|
|
import java.util.ArrayList;
|
|
import java.util.Random;
|
|
|
|
public class MyParametrClass<T extends EntityBattleship, U extends IDrawningBlocks> {
|
|
private final ArrayList<T> EntityArray;
|
|
private final ArrayList<U> BlocksArray;
|
|
int entitiesCount = 0;
|
|
int blocksCount = 0;
|
|
public MyParametrClass(int entitiesCount, int blocksCount) {
|
|
EntityArray = new ArrayList<T>();
|
|
BlocksArray = new ArrayList<U>();
|
|
}
|
|
public void Insert(T battleship){
|
|
|
|
EntityArray.add(battleship);
|
|
entitiesCount++;
|
|
|
|
}
|
|
public void Insert(U drawningBlocks){
|
|
|
|
BlocksArray.add(drawningBlocks);
|
|
blocksCount++;
|
|
|
|
}
|
|
public DrawningBattleship GetDrawningBattleship() {
|
|
|
|
Random random = new Random();
|
|
int entityIndex = random.nextInt(EntityArray.size());
|
|
int blockIndex = random.nextInt( BlocksArray.size());
|
|
|
|
|
|
EntityBattleship battleship = EntityArray.get(entityIndex);
|
|
IDrawningBlocks blocks = BlocksArray.get(blockIndex);
|
|
|
|
if (battleship instanceof EntityLinkor) {
|
|
return new DrawningLinkor(battleship, blocks);
|
|
}
|
|
return new DrawningLinkor(battleship, blocks);
|
|
}
|
|
}
|