PIbd-21_Potapov_N.S._Stormt.../ProjectStormtrooper/DoubleParametrized.java

42 lines
1.4 KiB
Java
Raw Normal View History

package ProjectStormtrooper;
import java.util.ArrayList;
import java.util.Random;
public class DoubleParametrized<T extends EntityPlane, U extends IDrawingEngines> {
ArrayList<T> _entityPlanes;
ArrayList<U> _drawingEngines;
public DoubleParametrized() {
_entityPlanes = new ArrayList<>();
_drawingEngines = new ArrayList<>();
}
public void Add(T entityPlaneObject) {
_entityPlanes.add(entityPlaneObject);
}
public void Add(U drawingEnginesObject) {
_drawingEngines.add(drawingEnginesObject);
}
public DrawingPlane GeneratePlane(int pictureWidth, int pictureHeight) {
Random random = new Random();
if (_entityPlanes.isEmpty()) {
return null;
}
T entityPlane = _entityPlanes.get(random.nextInt(_entityPlanes.size()));
U drawingEngine = null;
if (!_drawingEngines.isEmpty()) {
drawingEngine = _drawingEngines.get(random.nextInt(_drawingEngines.size()));
}
DrawingPlane drawingPlane;
if (entityPlane instanceof EntityStormtrooper) {
drawingPlane = new DrawingStormtrooper((EntityStormtrooper) entityPlane, drawingEngine, pictureWidth, pictureHeight);
} else {
drawingPlane = new DrawingPlane(entityPlane, drawingEngine, pictureWidth, pictureHeight);
}
return drawingPlane;
}
}