79 lines
2.0 KiB
Java
79 lines
2.0 KiB
Java
|
import java.util.Random;
|
||
|
|
||
|
public class DrawingEntities <T extends EntityPlane, U extends IAdditionalDrawingObject>
|
||
|
{
|
||
|
public EntityPlane[] _arrPlane;
|
||
|
public IAdditionalDrawingObject[] _arrWindow;
|
||
|
int countArrPlane = 0;
|
||
|
int countArrWindows = 0;
|
||
|
String _x_index;
|
||
|
String _y_index;
|
||
|
|
||
|
//конструктор
|
||
|
public DrawingEntities(int sizeArrPlane, int sizeArrAddElem)
|
||
|
{
|
||
|
_arrPlane = new EntityPlane[sizeArrPlane];
|
||
|
_arrWindow = new IAdditionalDrawingObject[sizeArrAddElem];
|
||
|
}
|
||
|
|
||
|
//добавить сущность-самолёт
|
||
|
public int Insert(T plane)
|
||
|
{
|
||
|
if(countArrPlane < _arrPlane.length)
|
||
|
{
|
||
|
_arrPlane[countArrPlane] = plane;
|
||
|
countArrPlane++;
|
||
|
|
||
|
return countArrPlane - 1;
|
||
|
}
|
||
|
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
//добавить кол-во и тип иллюминаторов
|
||
|
public int Insert(U addElement)
|
||
|
{
|
||
|
if(countArrWindows < _arrWindow.length)
|
||
|
{
|
||
|
_arrWindow[countArrWindows] = addElement;
|
||
|
countArrWindows++;
|
||
|
|
||
|
return countArrWindows - 1;
|
||
|
}
|
||
|
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
//фиксирование индексов
|
||
|
public void SetIndex(int indexFirst, int indexSecond)
|
||
|
{
|
||
|
_x_index = Integer.toString(indexFirst);
|
||
|
_y_index = Integer.toString(indexSecond);
|
||
|
}
|
||
|
|
||
|
public DrawingPlane CreatePlane()
|
||
|
{
|
||
|
Random rnd = new Random();
|
||
|
int indexPlane = 0;
|
||
|
int indexArrWindow = 0;
|
||
|
|
||
|
if(countArrPlane - 1 != 0 && countArrWindows - 1 != 0)
|
||
|
{
|
||
|
indexPlane = rnd.nextInt(0, countArrPlane - 1);
|
||
|
indexArrWindow = rnd.nextInt(0, countArrWindows - 1);
|
||
|
}
|
||
|
|
||
|
T plane = (T)_arrPlane[indexPlane];
|
||
|
U windows = (U)_arrWindow[indexArrWindow];
|
||
|
|
||
|
SetIndex(indexPlane, indexArrWindow);
|
||
|
|
||
|
if(plane instanceof EntityAirbus)
|
||
|
{
|
||
|
return new DrawingAirbus(plane, windows);
|
||
|
}
|
||
|
|
||
|
return new DrawingPlane(plane, windows);
|
||
|
}
|
||
|
}
|