PIbd-22_Chernyshev_G.J._29_.../Trolleybus/DrawingTrolleybus.java

40 lines
1.5 KiB
Java
Raw Permalink Normal View History

2023-11-11 21:48:58 +04:00
package Trolleybus;
import java.awt.*;
2023-11-13 22:25:33 +04:00
public class DrawingTrolleybus extends DrawingBus{
// Конструктор
public DrawingTrolleybus(int speed, double weight, Color bodyColor, Color additionalColor, boolean horns, boolean batteries, int width, int height)
2023-11-11 21:48:58 +04:00
{
2023-11-13 22:25:33 +04:00
super(speed, weight, bodyColor, width, height, 150, 95);
if (EntityBus != null)
2023-11-11 21:48:58 +04:00
{
2023-11-13 22:25:33 +04:00
EntityBus = new EntityTrolleybus(speed, weight, bodyColor, additionalColor, horns, batteries);
2023-11-11 21:48:58 +04:00
}
}
// Прорисовка объекта
2023-11-13 22:25:33 +04:00
@Override
2023-11-11 21:48:58 +04:00
public void DrawTransport(Graphics g)
{
2023-11-13 22:25:33 +04:00
if (!(EntityBus instanceof EntityTrolleybus trolleybus))
2023-11-11 21:48:58 +04:00
{
return;
}
2023-11-13 22:25:33 +04:00
super.DrawTransport(g);
2023-11-11 21:48:58 +04:00
Graphics2D g2d = (Graphics2D)g;
//Опциональные "рога"
2023-11-13 22:25:33 +04:00
g2d.setColor(trolleybus.getAdditionalColor());
if (trolleybus.Horns)
2023-11-11 21:48:58 +04:00
{
g2d.drawLine(_startPosX + 70, _startPosY + 30, _startPosX + 40, _startPosY);
g2d.drawLine(_startPosX + 70, _startPosY + 30, _startPosX + 60, _startPosY);
}
//Опциональный отсек для батареи
2023-11-13 22:25:33 +04:00
if (trolleybus.Batteries)
2023-11-11 21:48:58 +04:00
{
int[] xOfBatteries = {_startPosX + 70, _startPosX + 70, _startPosX + 100, _startPosX + 110};
int[] yOfBatteries = {_startPosY + 30, _startPosY + 25, _startPosY + 25, _startPosY + 30};
g2d.fillPolygon(xOfBatteries, yOfBatteries, 4);
}
}
}