Добавление доп. класса по заданию, доработка классов отрисовки DrawPlane и DrawAirbus для взаимодействия с ним.
This commit is contained in:
parent
fb505d1628
commit
e4aca29884
@ -2,13 +2,20 @@ import java.awt.*;
|
||||
|
||||
public class DrawingAirbus extends DrawingPlane
|
||||
{
|
||||
//Инициализаци свойств
|
||||
//Конструктор
|
||||
public DrawingAirbus(int speed, int weight, Color corpusColor, Color addColor, boolean addCompartment, boolean addEngine)
|
||||
{
|
||||
super(speed, weight, corpusColor, 70, 30);
|
||||
Plane = new EntityAirbus(speed, weight, corpusColor, addColor, addCompartment, addEngine);
|
||||
}
|
||||
|
||||
//Второй конструктор
|
||||
public DrawingAirbus(EntityPlane plane, IAdditionalDrawingObject addWindows)
|
||||
{
|
||||
super(plane, addWindows);
|
||||
Plane = plane;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void DrawTransport(Graphics g)
|
||||
{
|
||||
|
78
Project/src/DrawingEntities.java
Normal file
78
Project/src/DrawingEntities.java
Normal file
@ -0,0 +1,78 @@
|
||||
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);
|
||||
}
|
||||
}
|
@ -65,6 +65,13 @@ public class DrawingPlane extends JPanel
|
||||
_airbusHeight = planeHeight;
|
||||
}
|
||||
|
||||
//второй конструктор
|
||||
public DrawingPlane(EntityPlane plane, IAdditionalDrawingObject countWindow)
|
||||
{
|
||||
Plane = plane;
|
||||
_airplaneWindow = countWindow;
|
||||
}
|
||||
|
||||
//установка координат позиции самолёта
|
||||
public void SetPosition(int x, int y, int width, int height)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user