2022-11-10 23:39:05 +04:00
|
|
|
import java.lang.reflect.Array;
|
2022-11-06 13:43:57 +04:00
|
|
|
import java.util.Random;
|
|
|
|
|
|
|
|
public class DrawingEntities <T extends EntityPlane, U extends IAdditionalDrawingObject>
|
|
|
|
{
|
2022-11-10 23:39:05 +04:00
|
|
|
public T[] _arrPlane;
|
|
|
|
public U[] _arrWindow;
|
2022-11-06 13:43:57 +04:00
|
|
|
int countArrPlane = 0;
|
|
|
|
int countArrWindows = 0;
|
|
|
|
String _x_index;
|
|
|
|
String _y_index;
|
|
|
|
|
|
|
|
//конструктор
|
2022-11-10 23:39:05 +04:00
|
|
|
public DrawingEntities(int sizeArr, Class<T> objectT, Class<U> objectU)
|
2022-11-06 13:43:57 +04:00
|
|
|
{
|
2022-11-10 23:39:05 +04:00
|
|
|
final T[] arrPlane = (T[]) Array.newInstance(objectT, sizeArr);
|
|
|
|
_arrPlane = arrPlane;
|
|
|
|
|
|
|
|
final U[] arrWindod = (U[]) Array.newInstance(objectU, sizeArr);
|
|
|
|
_arrWindow = arrWindod;
|
2022-11-06 13:43:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//добавить сущность-самолёт
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|