51 lines
1.4 KiB
Java
51 lines
1.4 KiB
Java
import java.util.Random;
|
|
|
|
public class AircraftMixer<T extends EntityAircraft, U extends IDrawingEngines> {
|
|
private T[] aircrafts;
|
|
private U[] engines;
|
|
|
|
public AircraftMixer(int countAircrafts, int countEngines) {
|
|
aircrafts = (T[])(new EntityAircraft[countAircrafts]);
|
|
engines = (U[])(new IDrawingEngines[countEngines]);
|
|
}
|
|
|
|
public int add(T a) {
|
|
int index = 0;
|
|
while(index < aircrafts.length && aircrafts[index] != null) index++;
|
|
|
|
if(index == aircrafts.length) return -1;
|
|
|
|
aircrafts[index] = a;
|
|
return index;
|
|
}
|
|
|
|
public int add(U e) {
|
|
int index = 0;
|
|
while(index < engines.length && engines[index] != null) index++;
|
|
|
|
if(index == engines.length) return -1;
|
|
|
|
engines[index] = e;
|
|
return index;
|
|
}
|
|
|
|
public DrawingAircraft constructAircraft(int width, int height) {
|
|
Random rnd = new Random();
|
|
|
|
DrawingAircraft air;
|
|
|
|
T selectedAircraft = aircrafts[rnd.nextInt(0, aircrafts.length)];
|
|
U selectedEngines = engines[rnd.nextInt(0, engines.length)];
|
|
|
|
DrawingAircraft result;
|
|
|
|
if(selectedAircraft instanceof EntityModernAircraft) {
|
|
result = new DrawingModernAircraft(selectedAircraft, selectedEngines);
|
|
}
|
|
else result = new DrawingAircraft(selectedAircraft, selectedEngines);
|
|
|
|
result.SetPosition(10, 10, width, height);
|
|
return result;
|
|
}
|
|
}
|