import java.awt.*; public class DrawingCrane { private EntityCrane entityCrane; private DrawingWheel drawingWheel; private int _pictureWidth; private int _pictureHeight; private int _startPositionX; private int _startPositionY; private final int _craneWidth = 200; private final int _craneHeight = 150; public void Init(int speed, double weight, boolean counterWeight, boolean crane, Color bodyColor, Color additionalColor, int width, int height,int wheelCount) { if ((_craneWidth > width) || (_craneHeight > height)) return; _pictureHeight = height; _pictureWidth = width; entityCrane = new EntityCrane(); entityCrane.Init(speed, weight, counterWeight,crane, bodyColor, additionalColor); drawingWheel = new DrawingWheel(); drawingWheel.SetWheelCounter(wheelCount); } public void SetPosition(int x, int y) { if(x+_craneWidth>_pictureWidth) { while(x + _craneWidth > _pictureWidth) { x -= _pictureWidth; } } _startPositionX = x; if(y+_craneHeight>_pictureHeight) { while(y+_craneHeight>_pictureHeight) { y -= _pictureHeight; } } _startPositionY = y; } public void MoveCrane(DirectionType direction) { if (entityCrane == null) return; switch (direction) { case Left -> { if (_startPositionX - entityCrane.Step > 0) { _startPositionX -= (int) entityCrane.Step; } } case Right->{ if (_startPositionX + entityCrane.Step + _craneWidth < _pictureWidth) { _startPositionX += (int) entityCrane.Step; } } case Up-> { if (_startPositionY - entityCrane.Step > 0) { _startPositionY -= (int) entityCrane.Step; } } case Down ->{ if (_startPositionY + entityCrane.Step + _craneHeight < _pictureHeight) { _startPositionY += (int) entityCrane.Step; } } } } public void DrawTransport(Graphics g) { var g2d = (Graphics2D)g; if (entityCrane == null) return; // Гусеницы g2d.drawLine( _startPositionX + 5, _startPositionY + 110, _startPositionX + 195, _startPositionY + 110); g2d.drawLine( _startPositionX, _startPositionY + 115, _startPositionX, _startPositionY + 145); g2d.drawLine( _startPositionX + 5, _startPositionY + 150, _startPositionX + 195, _startPositionY + 150); g2d.drawLine( _startPositionX + 200, _startPositionY + 115, _startPositionX + 200, _startPositionY + 145); g2d.drawArc( _startPositionX, _startPositionY + 110, _craneWidth / 20, _craneHeight / 15, 45, 135); g2d.drawArc( _startPositionX, _startPositionY + 140, _craneWidth / 20, _craneHeight / 15, 135, 180); g2d.drawArc( _startPositionX + 190, _startPositionY + 110, _craneWidth / 20, _craneHeight / 20, 305, 170); g2d.drawArc( _startPositionX + 190, _startPositionY + 143, _craneWidth / 20, _craneHeight / 20, 230, 180); // основное тело g2d.setColor(entityCrane.getBodyColor()); g2d.drawRect( _startPositionX + 10, _startPositionY + 65, 180, 40); g2d.fillRect( _startPositionX + 10, _startPositionY + 65, 180, 40); g2d.setColor(Color.BLACK); drawingWheel.DrawWheels(_startPositionX, _startPositionY, g2d); //кабинка и выхлоп g2d.drawRect( _startPositionX + 60, _startPositionY + 10, 20, 55); g2d.drawRect( _startPositionX + 110, _startPositionY, 75, 65); if (entityCrane.getCounterWeight()) { g2d.setColor(entityCrane.getAdditionalColor()); g2d.drawRect( _startPositionX + 185, _startPositionY + 20, 15, 45); } if (entityCrane.getCrane()) { g2d.drawRect( _startPositionX + 20, _startPositionY, 30, 65); g2d.drawRect( _startPositionX, _startPositionY, 20, 30); g2d.fillRect( _startPositionX + 20, _startPositionY, 30, 65); g2d.fillRect( _startPositionX, _startPositionY, 20, 30); } } }