import java.awt.*; public class DrawningBulldozer { private EntityBulldozer entityBulldozer; public EntityBulldozer getEntityBulldozer() { return entityBulldozer; } private DrawningWheels drawningWheels; private int _pictureWidth; private int _pictureHeight; private int _startPosX; private int _startPosY; private int _bulldozerWidth = 160; private int _bulldozerHeight = 80; public boolean Init(int speed, double weight, Color bulldozerColor, Color cabinColor, Color covshColor, boolean hasMoldboardfront, boolean hasRipper, int width, int height, int wheelNumber) { if (height < _bulldozerHeight || width < _bulldozerWidth) { return false; } _pictureWidth = width; _pictureHeight = height; entityBulldozer = new EntityBulldozer(); entityBulldozer.Init(speed, weight, bulldozerColor, cabinColor, covshColor, hasMoldboardfront, hasRipper); drawningWheels = new DrawningWheels(); drawningWheels.setWheelNumber(wheelNumber); return true; } public void SetPosition(int x, int y) { if (x < 0 || x + _bulldozerWidth > _pictureWidth) { x = 0; } if (y < 0 || y + _bulldozerHeight > _pictureHeight) { y = 0; } _startPosX = x; _startPosY = y; } public void MoveTransport(DirectionBulldozer direction) { if (entityBulldozer == null) return; switch (direction) { //влево case Left: if (_startPosX - entityBulldozer.getStep() > 0) { _startPosX -= (int)entityBulldozer.getStep(); } break; //вверх case Up: if (_startPosY - entityBulldozer.getStep() > 0) { _startPosY -= (int)entityBulldozer.getStep(); } break; //вправо case Right: if (_startPosX + _bulldozerWidth + entityBulldozer.getStep() < _pictureWidth) { _startPosX += (int)entityBulldozer.getStep(); } break; //вниз case Down: if (_startPosY + _bulldozerHeight + entityBulldozer.getStep() < _pictureHeight) { _startPosY += (int)entityBulldozer.getStep(); } break; } } public void DrawTransport(Graphics2D g2D) { if (entityBulldozer == null) { return; } g2D.setStroke(new BasicStroke(3)); g2D.setPaint(entityBulldozer.getBulldozerColor()); g2D.fillRect(_startPosX + 25, _startPosY + 20, 110, 30); g2D.fillRect(_startPosX+60, _startPosY, 10, 30); int x = _startPosX + 30; // начальная позиция X int y = _startPosY; // начальная позиция Y int width = 110; // ширина прямоугольника int height = 30; // высота прямоугольника int radius = 20; // радиус закругления углов // Рисуем закругленный прямоугольник g2D.setColor(Color.BLACK); g2D.drawArc(x - 5, y + 50, radius * 2, radius * 2, 180, 90); // верхний левый угол g2D.drawLine(x + radius - 5, y + 50, x + width - radius - 5, y + 50); // верхняя горизонталь g2D.drawArc(x + width - radius * 2 - 5, y + 50, radius * 2, radius * 2, 270, 90); // верхний правый угол g2D.drawArc(x + width - radius * 2 - 5, y + height - radius * 2 + 60, radius * 2, radius * 2, 0, 90); // нижний правый угол g2D.drawLine(x + width - radius - 5, y + height + 60, x + radius - 5, y + height + 60); // нижняя горизонталь g2D.drawArc(x - 5, y + height - radius * 2 + 60, radius * 2, radius * 2, 90, 90); // нижний левый угол // Кабина g2D.setPaint(entityBulldozer.getCabinColor()); g2D.fillRect(_startPosX + 105, _startPosY, 30, 20); //Колёса drawningWheels.drawWheels(g2D, Color.BLACK, _startPosX, _startPosY); if (entityBulldozer.getHasMoldboardfront()) { g2D.setPaint(entityBulldozer.getCabinColor()); int[] xPoints = {_startPosX + 25, _startPosX + 25, _startPosX}; int[] yPoints = {_startPosY + 30, _startPosY + 80, _startPosY + 80}; Polygon triangle = new Polygon(xPoints, yPoints, 3); g2D.drawPolygon(triangle); } if (entityBulldozer.getHasRipper()) { int[] xPoints2 = {_startPosX + 130, _startPosX + 160, _startPosX + 160}; int[] yPoints2 = {_startPosY + 50, _startPosY + 50, _startPosY + 80}; Polygon triangle2 = new Polygon(xPoints2, yPoints2, 3); g2D.drawPolygon(triangle2); } } }