125 lines
5.8 KiB
Java
125 lines
5.8 KiB
Java
|
import java.awt.*;
|
|||
|
public class DrawingTrolleybus {
|
|||
|
private EntityTrolleybus entityTrolleybus;
|
|||
|
public EntityTrolleybus getEntityTrolleybus() {
|
|||
|
return entityTrolleybus;
|
|||
|
}
|
|||
|
private int _pictureWidth;
|
|||
|
private int _pictureHeight;
|
|||
|
private int _startPosX;
|
|||
|
private int _startPosY;
|
|||
|
private final int trolleybusWidth = 200;
|
|||
|
private final int trolleybusHeight = 135;
|
|||
|
private DrawingDoors drawingDoors;
|
|||
|
public boolean init(int speed, double weight, Color bodyColor, Color additionalColor,
|
|||
|
boolean roga, boolean battery, int width, int height, int doorsNumber)
|
|||
|
{
|
|||
|
if (width < trolleybusWidth || height < trolleybusHeight)
|
|||
|
return false;
|
|||
|
_pictureWidth = width;
|
|||
|
_pictureHeight = height;
|
|||
|
entityTrolleybus = new EntityTrolleybus();
|
|||
|
entityTrolleybus.init(speed, weight, bodyColor, additionalColor, roga, battery);
|
|||
|
drawingDoors = new DrawingDoors();
|
|||
|
drawingDoors.getNumber(doorsNumber);
|
|||
|
return true;
|
|||
|
}
|
|||
|
public void setPosition(int x, int y)
|
|||
|
{
|
|||
|
if (x < 0 || y < 0 || x + trolleybusWidth >= _pictureWidth || y + trolleybusHeight >= _pictureHeight) {
|
|||
|
x = 0;
|
|||
|
y = 0;
|
|||
|
}
|
|||
|
_startPosX = x;
|
|||
|
_startPosY = y;
|
|||
|
}
|
|||
|
public void moveTransport(DirectionType direction) {
|
|||
|
if (entityTrolleybus == null)
|
|||
|
return;
|
|||
|
switch (direction) {
|
|||
|
//влево
|
|||
|
case LEFT:
|
|||
|
if (_startPosX - entityTrolleybus.step.get().intValue() > 0)
|
|||
|
_startPosX -= entityTrolleybus.step.get().intValue();
|
|||
|
break;
|
|||
|
//вверх
|
|||
|
case UP:
|
|||
|
if (_startPosY - entityTrolleybus.step.get().intValue() > 0)
|
|||
|
_startPosY -= entityTrolleybus.step.get().intValue();
|
|||
|
break;
|
|||
|
// вправо
|
|||
|
case RIGHT:
|
|||
|
if (_startPosX + trolleybusWidth + entityTrolleybus.step.get().intValue() < _pictureWidth)
|
|||
|
_startPosX += entityTrolleybus.step.get().intValue();
|
|||
|
break;
|
|||
|
//вниз
|
|||
|
case DOWN:
|
|||
|
if (_startPosY + trolleybusHeight + entityTrolleybus.step.get().intValue() < _pictureHeight)
|
|||
|
_startPosY += entityTrolleybus.step.get().intValue();
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
public void drawTransport(Graphics2D graphics2D) {
|
|||
|
if (entityTrolleybus == null)
|
|||
|
return;
|
|||
|
BasicStroke pen = new BasicStroke(2);
|
|||
|
graphics2D.setStroke(pen);
|
|||
|
Color bodyColor = entityTrolleybus.getBodyColor();
|
|||
|
Color additionalColor = entityTrolleybus.getAdditionalColor();
|
|||
|
//колеса
|
|||
|
graphics2D.setPaint(Color.BLACK);
|
|||
|
graphics2D.fillOval(_startPosX + 31, _startPosY + 106, 30, 30);
|
|||
|
graphics2D.fillOval(_startPosX + 151, _startPosY + 106, 30, 30);
|
|||
|
//кузов
|
|||
|
graphics2D.setPaint(bodyColor);
|
|||
|
graphics2D.fillRect(_startPosX + 6, _startPosY + 31, 200, 90);
|
|||
|
//стекла
|
|||
|
graphics2D.setPaint(Color.BLUE);
|
|||
|
graphics2D.fillRect(_startPosX + 186, _startPosY + 40, 20, 40);
|
|||
|
graphics2D.fillOval(_startPosX + 151, _startPosY + 35, 30, 40);
|
|||
|
graphics2D.fillOval(_startPosX + 118, _startPosY + 35, 30, 40);
|
|||
|
graphics2D.fillOval(_startPosX + 85, _startPosY + 35, 30, 40);
|
|||
|
graphics2D.fillOval(_startPosX + 52, _startPosY + 35, 30, 40);
|
|||
|
graphics2D.fillOval(_startPosX + 19, _startPosY + 35, 30, 40);
|
|||
|
//двери
|
|||
|
graphics2D.setPaint(Color.BLACK);
|
|||
|
drawingDoors.drawDoors(graphics2D, _startPosX, _startPosY);
|
|||
|
//рога
|
|||
|
graphics2D.setPaint(Color.BLACK);
|
|||
|
if (entityTrolleybus.getRoga()) {
|
|||
|
graphics2D.setPaint(Color.BLACK);
|
|||
|
graphics2D.drawLine(_startPosX + 186, _startPosY + 31, _startPosX + 86, _startPosY + 1);
|
|||
|
graphics2D.drawLine(_startPosX + 86, _startPosY + 1, _startPosX + 126, _startPosY + 31);
|
|||
|
graphics2D.drawLine(_startPosX + 146, _startPosY + 31, _startPosX + 46, _startPosY + 1);
|
|||
|
graphics2D.drawLine(_startPosX + 46, _startPosY + 1, _startPosX + 86, _startPosY + 31);
|
|||
|
}
|
|||
|
//батарея
|
|||
|
if (entityTrolleybus.getBattery()) {
|
|||
|
graphics2D.setPaint(additionalColor);
|
|||
|
graphics2D.fillRect(_startPosX + 176, _startPosY + 101, 15, 20);
|
|||
|
graphics2D.setPaint(Color.YELLOW);
|
|||
|
graphics2D.drawLine(_startPosX + 183, _startPosY + 103, _startPosX + 178, _startPosY + 111);
|
|||
|
graphics2D.drawLine(_startPosX + 178, _startPosY + 111, _startPosX + 189, _startPosY + 111);
|
|||
|
graphics2D.drawLine(_startPosX + 189, _startPosY + 111, _startPosX + 183, _startPosY + 119);
|
|||
|
}
|
|||
|
//границы троллейбуса
|
|||
|
graphics2D.setPaint(Color.BLACK);
|
|||
|
graphics2D.drawRect(_startPosX + 6, _startPosY + 31, 200, 90);
|
|||
|
graphics2D.drawOval(_startPosX + 151, _startPosY + 35, 30, 40);
|
|||
|
graphics2D.drawOval(_startPosX + 118, _startPosY + 35, 30, 40);
|
|||
|
graphics2D.drawOval(_startPosX + 85, _startPosY + 35, 30, 40);
|
|||
|
graphics2D.drawOval(_startPosX + 52, _startPosY + 35, 30, 40);
|
|||
|
graphics2D.drawOval(_startPosX + 19, _startPosY + 35, 30, 40);
|
|||
|
graphics2D.drawRect(_startPosX + 186, _startPosY + 40, 20, 40);
|
|||
|
//задние фары
|
|||
|
graphics2D.setPaint(Color.RED);
|
|||
|
graphics2D.fillRect(_startPosX + 6, _startPosY + 91, 10, 20);
|
|||
|
graphics2D.setPaint(Color.BLACK);
|
|||
|
graphics2D.drawRect(_startPosX + 6, _startPosY + 91, 10, 20);
|
|||
|
//передние фары
|
|||
|
graphics2D.setPaint(Color.YELLOW);
|
|||
|
graphics2D.fillRect(_startPosX + 196, _startPosY + 91, 10, 20);
|
|||
|
graphics2D.setPaint(Color.BLACK);
|
|||
|
graphics2D.drawRect(_startPosX + 196, _startPosY + 91, 10, 20);
|
|||
|
}
|
|||
|
}
|