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