2022-12-20 21:50:09 +04:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Random;
|
|
|
|
|
|
|
|
public class MyParametrClass<T extends EntityBattleship, U extends IDrawningBlocks> {
|
2022-12-22 22:27:39 +04:00
|
|
|
private final ArrayList<T> EntityArray;
|
|
|
|
private final ArrayList<U> BlocksArray;
|
2022-12-20 21:50:09 +04:00
|
|
|
int entitiesCount = 0;
|
|
|
|
int blocksCount = 0;
|
|
|
|
public MyParametrClass(int entitiesCount, int blocksCount) {
|
2022-12-22 22:27:39 +04:00
|
|
|
EntityArray = new ArrayList<T>();
|
|
|
|
BlocksArray = new ArrayList<U>();
|
2022-12-20 21:50:09 +04:00
|
|
|
}
|
|
|
|
public void Insert(T battleship){
|
2022-12-22 22:27:39 +04:00
|
|
|
|
|
|
|
EntityArray.add(battleship);
|
2022-12-20 21:50:09 +04:00
|
|
|
entitiesCount++;
|
2022-12-22 22:27:39 +04:00
|
|
|
|
2022-12-20 21:50:09 +04:00
|
|
|
}
|
|
|
|
public void Insert(U drawningBlocks){
|
2022-12-22 22:27:39 +04:00
|
|
|
|
|
|
|
BlocksArray.add(drawningBlocks);
|
2022-12-20 21:50:09 +04:00
|
|
|
blocksCount++;
|
2022-12-22 22:27:39 +04:00
|
|
|
|
2022-12-20 21:50:09 +04:00
|
|
|
}
|
|
|
|
public DrawningBattleship GetDrawningBattleship() {
|
|
|
|
|
|
|
|
Random random = new Random();
|
2022-12-22 22:27:39 +04:00
|
|
|
int entityIndex = random.nextInt(EntityArray.size());
|
|
|
|
int blockIndex = random.nextInt( BlocksArray.size());
|
|
|
|
|
2022-12-20 21:50:09 +04:00
|
|
|
|
2022-12-22 22:27:39 +04:00
|
|
|
EntityBattleship battleship = EntityArray.get(entityIndex);
|
|
|
|
IDrawningBlocks blocks = BlocksArray.get(blockIndex);
|
2022-12-20 21:50:09 +04:00
|
|
|
|
|
|
|
if (battleship instanceof EntityLinkor) {
|
|
|
|
return new DrawningLinkor(battleship, blocks);
|
|
|
|
}
|
|
|
|
return new DrawningLinkor(battleship, blocks);
|
|
|
|
}
|
|
|
|
}
|