PIbd-23_Dolgov_D.A._Airbus..../DrawingAirbus.java

196 lines
6.9 KiB
Java
Raw Normal View History

2022-10-17 23:06:21 +04:00
import java.awt.*;
2022-12-05 18:09:08 +04:00
import java.util.Random;
2022-11-21 23:55:09 +04:00
public class DrawingAirbus {
public EntityAirbus Airbus;
2022-12-05 18:09:08 +04:00
protected float _startPosX;
protected float _startPosY;
2022-10-17 23:06:21 +04:00
private Integer _pictureWidth = null;
private Integer _pictureHeight = null;
2022-12-05 18:09:08 +04:00
private int _airbusWidth = 125;
private int _airbusHeight = 45;
public IDrawingIlum drawingilum;
2022-10-17 23:06:21 +04:00
2022-12-05 18:09:08 +04:00
private final Random random = new Random();
public DrawingAirbus(int speed, float weight, Color bodyColor)
{
int randExtra = random.nextInt(2);
switch (random.nextInt(3)){
2022-12-05 21:01:53 +04:00
case 0:
drawingilum = new DrawingPlusIlum(randExtra);
2022-12-05 18:09:08 +04:00
break;
case 1:
drawingilum = new DrawingSquareIlum(randExtra);
break;
case 2:
drawingilum = new DrawingIlum(randExtra, bodyColor);
2022-12-05 21:01:53 +04:00
break;
2022-12-05 18:09:08 +04:00
}
Airbus = new EntityAirbus(speed, weight, bodyColor);
}
// Новый конструктор
protected DrawingAirbus (int speed, float weight, Color bodyColor, int airbusWidth, int airbusHeight)
2022-10-17 23:06:21 +04:00
{
2022-12-05 18:09:08 +04:00
this(speed, weight, bodyColor);
_airbusWidth = airbusWidth;
_airbusHeight = airbusHeight;
2022-10-17 23:06:21 +04:00
}
public void SetPosition(int x, int y, int width, int height)
{
2022-11-21 23:55:09 +04:00
if (x < 0 || x + _airbusWidth >= width)
2022-10-17 23:06:21 +04:00
{
return;
}
2022-11-21 23:55:09 +04:00
if (y < 0 || y + _airbusHeight >= height)
2022-10-17 23:06:21 +04:00
{
return;
}
_startPosX = x;
_startPosY = y;
_pictureWidth = width;
_pictureHeight = height;
}
public void MoveTransport(Direction direction)
{
if (_pictureWidth == null || _pictureHeight == null)
{
return;
}
switch (direction)
{
// вправо
case Right:
2022-11-21 23:55:09 +04:00
if (_startPosX + _airbusWidth + Airbus.Step() < _pictureWidth)
2022-10-17 23:06:21 +04:00
{
2022-11-21 23:55:09 +04:00
_startPosX += Airbus.Step();
2022-10-17 23:06:21 +04:00
}
2022-11-21 23:55:09 +04:00
else _startPosX = _pictureWidth - _airbusWidth;
2022-10-17 23:06:21 +04:00
break;
//влево
case Left:
2022-11-21 23:55:09 +04:00
if (_startPosX - Airbus.Step() >= 0)
2022-10-17 23:06:21 +04:00
{
2022-11-21 23:55:09 +04:00
_startPosX -= Airbus.Step();
2022-10-17 23:06:21 +04:00
}
else _startPosX = 0;
2022-10-17 23:06:21 +04:00
break;
//вверх
case Up:
2022-11-21 23:55:09 +04:00
if (_startPosY - Airbus.Step() >= 0)
2022-10-17 23:06:21 +04:00
{
2022-11-21 23:55:09 +04:00
_startPosY -= Airbus.Step();
2022-10-17 23:06:21 +04:00
}
else _startPosY = 0;
2022-10-17 23:06:21 +04:00
break;
//вниз
case Down:
2022-11-21 23:55:09 +04:00
if (_startPosY + _airbusHeight + Airbus.Step() < _pictureHeight)
2022-10-17 23:06:21 +04:00
{
2022-11-21 23:55:09 +04:00
_startPosY += Airbus.Step();
2022-10-17 23:06:21 +04:00
}
2022-11-21 23:55:09 +04:00
else _startPosY = _pictureHeight - _airbusWidth;
2022-10-17 23:06:21 +04:00
break;
}
}
public void DrawTransport(Graphics2D g)
2022-10-17 23:06:21 +04:00
{
if (_startPosX < 0 || _startPosY < 0
|| _pictureHeight == null|| _pictureWidth == 0)
{
return;
}
g.setColor(Color.black);
2022-10-17 23:06:21 +04:00
g.drawOval((int)_startPosX, (int)_startPosY + 20, 20, 20);
g.drawRect((int)_startPosX + 8, (int)_startPosY + 20, 100, 20);
g.drawPolygon
(
new int[] {(int)_startPosX + 108, (int)_startPosX + 125, (int)_startPosX + 108},
new int[] {(int)_startPosY + 18, (int)_startPosY + 30, (int)_startPosY + 30}, 3
);
g.drawPolygon
(
new int[] {(int)_startPosX + 108, (int)_startPosX + 125, (int)_startPosX + 108},
new int[] {(int)_startPosY + 30, (int)_startPosY + 30, (int)_startPosY + 42}, 3
);
g.drawPolygon
(
new int[] {(int)_startPosX + 5, (int)_startPosX + 5, (int)_startPosX + 35},
new int[] {(int)_startPosY + 20, (int)_startPosY, (int)_startPosY + 20}, 3
);
// корпус
2022-11-21 23:55:09 +04:00
g.setColor(Airbus.getBodyColor());
2022-10-17 23:06:21 +04:00
g.fillOval((int)_startPosX, (int)_startPosY + 20, 20, 20);
g.fillRect((int)_startPosX + 8, (int)_startPosY + 20, 100, 20);
g.fillPolygon
(
new int[] {(int)_startPosX + 108, (int)_startPosX + 125, (int)_startPosX + 108},
new int[] {(int)_startPosY + 30, (int)_startPosY + 30, (int)_startPosY + 42}, 3
);
g.fillPolygon
(
new int[] {(int)_startPosX + 5, (int)_startPosX + 5, (int)_startPosX + 35},
new int[] {(int)_startPosY + 20, (int)_startPosY, (int)_startPosY + 20}, 3
);
g.setColor(Color.blue);
for (int tempX = 98; tempX > 38; tempX -= 6) {
g.fillOval((int) _startPosX + tempX, (int)_startPosY + 20, 4, 4);
}
drawingilum.DrawIl((int)_startPosX, (int)_startPosY, g);
2022-10-17 23:06:21 +04:00
g.fillPolygon
(
new int[] {(int)_startPosX + 108, (int)_startPosX + 125, (int)_startPosX + 108},
new int[] {(int)_startPosY + 18, (int)_startPosY + 30, (int)_startPosY + 30}, 3
);
g.setColor(Color.black);
g.drawLine((int)_startPosX + 37, (int)_startPosY + 40, (int)_startPosX + 37, (int)_startPosY + 45);
g.drawLine((int)_startPosX + 32, (int)_startPosY + 45, (int)_startPosX + 40, (int)_startPosY + 45);
g.fillRect((int)_startPosX + 32, (int)_startPosY + 45, 3, 3);
g.fillRect((int)_startPosX + 39, (int)_startPosY + 45, 3, 3);
g.drawLine((int)_startPosX + 102, (int)_startPosY + 40, (int)_startPosX + 102, (int)_startPosY + 45);
g.fillRect((int)_startPosX + 101, (int)_startPosY + 45, 3, 3);
g.fillRect((int)_startPosX + 5, (int)_startPosY + 18, 18, 7);
g.fillOval((int)_startPosX, (int)_startPosY + 18, 7, 7);
g.fillOval((int)_startPosX + 20, (int)_startPosY + 18, 7, 7);
g.fillRect((int)_startPosX + 41, (int)_startPosY + 34, 42, 4);
g.fillOval((int)_startPosX + 39, (int)_startPosY + 34, 4, 4);
g.fillOval((int)_startPosX + 81, (int)_startPosY + 34, 4, 4);
2022-10-17 23:06:21 +04:00
}
public void ChangeBorders(int width, int height)
{
_pictureWidth = width;
_pictureHeight = height;
2022-11-21 23:55:09 +04:00
if (_pictureWidth <= _airbusWidth || _pictureHeight <= _airbusHeight)
2022-10-17 23:06:21 +04:00
{
_pictureWidth = null;
_pictureHeight = null;
return;
}
2022-11-21 23:55:09 +04:00
if (_startPosX + _airbusWidth > _pictureWidth)
2022-10-17 23:06:21 +04:00
{
2022-11-21 23:55:09 +04:00
_startPosX = _pictureWidth - _airbusWidth;
2022-10-17 23:06:21 +04:00
}
2022-11-21 23:55:09 +04:00
if (_startPosY + _airbusHeight > _pictureHeight)
2022-10-17 23:06:21 +04:00
{
2022-11-21 23:55:09 +04:00
_startPosY = _pictureHeight - _airbusHeight;
2022-10-17 23:06:21 +04:00
}
}
2022-12-05 18:09:08 +04:00
public float[] GetCurrentPosition()
{
return new float[] {/*UP*/_startPosY, /*RIGHT*/ _startPosX + _airbusWidth, /*DOWN*/ _startPosY + _airbusHeight, /*LEFT*/ _startPosX};
}
2022-10-17 23:06:21 +04:00
}