import java.awt.*; public class DrawingContainerShip extends DrawingShip { private Color dopColor; public DrawingContainerShip(int speed, float weight, Color bodyColor,int numdeck,Color dopColor,boolean crane,boolean containers) { super(speed,weight,bodyColor,numdeck,130,45); Ship = new EntityContainerShip(speed, weight, bodyColor, dopColor, crane, containers); this.dopColor=dopColor; } protected DrawingContainerShip(EntityShip ship,IAdditionalDrawingObject deck) { super(ship,deck); Ship=ship; } public void SetDopColor(Color color) { var temp = (EntityContainerShip) Ship; Ship=new EntityContainerShip(temp.GetSpeed(),temp.GetWeight(),temp.GetBodyColor(),color,temp.GetCrane(),temp.GetContainers()); dopColor=color; } @Override public void SetColor(Color color) { var temp = (EntityContainerShip) Ship; dopColor = dopColor==null? Color.WHITE : dopColor; Ship=new EntityContainerShip(temp.GetSpeed(),temp.GetWeight(),color,dopColor,temp.GetCrane(),temp.GetContainers()); } @Override public void DrawTransport(Graphics g) { if (!(GetShip() instanceof EntityContainerShip containerShip)) { return; } super.DrawTransport(g); Graphics2D g2d = (Graphics2D) g; Deck.DrawDeck(Ship.GetBodyColor(), g, _startPosX, _startPosY); if (containerShip.GetContainers()) { g2d.setPaint(containerShip.GetDopColor()); //Заливка контейнеров int[] xValuesFirstContainer = {(int) _startPosX + 16, (int) _startPosX + 16 + 29, (int) _startPosX + 16 + 29, (int) _startPosX + 16}; int[] yValuesFirstContainer = {(int) _startPosY + 16, (int) _startPosY + 16, (int) _startPosY + 16 + 14, (int) _startPosY + 16 + 14}; g2d.fillPolygon(xValuesFirstContainer, yValuesFirstContainer, 4); int[] xValuesSecondContainer = {(int) _startPosX + 56, (int) _startPosX + 56 + 29, (int) _startPosX + 56 + 29, (int) _startPosX + 56}; int[] yValuesSecondContainer = {(int) _startPosY + 16, (int) _startPosY + 16, (int) _startPosY + 16 + 14, (int) _startPosY + 16 + 14}; g2d.fillPolygon(xValuesSecondContainer, yValuesSecondContainer, 4); //Заливка центральных полос на контейнерах g2d.setPaint(Color.ORANGE); int[] xValuesFirstContainerLine = {(int) _startPosX + 16, (int) _startPosX + 16 + 29, (int) _startPosX + 16 + 29, (int) _startPosX + 16}; int[] yValuesFirstContainerLine = {(int) _startPosY + 20, (int) _startPosY + 20, (int) _startPosY + 25, (int) _startPosY + 25}; g2d.fillPolygon(xValuesFirstContainerLine, yValuesFirstContainerLine, 4); int[] xValuesSecondContainerLine = {(int) _startPosX + 56, (int) _startPosX + 56 + 29, (int) _startPosX + 56 + 29, (int) _startPosX + 56}; int[] yValuesSecondContainerLine = {(int) _startPosY + 20, (int) _startPosY + 20, (int) _startPosY + 25, (int) _startPosY + 25}; g2d.fillPolygon(xValuesSecondContainerLine, yValuesSecondContainerLine, 4); //Границы контейнеров g2d.setPaint(Color.BLACK); g2d.drawPolygon(xValuesFirstContainer, yValuesFirstContainer, 4); g2d.drawPolygon(xValuesSecondContainer, yValuesSecondContainer, 4); } if (containerShip.GetCrane()) { int[] xValuesBorderTown = {(int) _startPosX + 45, (int) _startPosX + 55, (int) _startPosX + 55, (int) _startPosX + 45}; int[] yValuesBorderTown = {(int) _startPosY, (int) _startPosY, (int) _startPosY + 30, (int) _startPosY + 30}; g.drawPolygon(xValuesBorderTown, yValuesBorderTown, 4); g.fillPolygon(xValuesBorderTown, yValuesBorderTown, 4); //Граница заливки стрелы крана int[] xValuesBorderCrane = {(int) _startPosX + 50, (int) _startPosX + 90, (int) _startPosX + 50}; int[] yValuesBorderCrane = {(int) _startPosY + 10, (int) _startPosY + 13, (int) _startPosY + 16}; g2d.fillPolygon(xValuesBorderCrane,yValuesBorderCrane,3); //Трос и крепление g2d.setColor(Color.BLACK); g2d.drawLine((int)_startPosX + 90, (int)_startPosY + 14, (int)_startPosX + 90, (int)_startPosY + 40); g2d.drawLine((int)_startPosX + 90, (int)_startPosY + 40, (int)_startPosX + 85, (int)_startPosY + 43); g2d.drawLine((int)_startPosX + 90, (int)_startPosY + 40, (int)_startPosX + 90, (int)_startPosY + 45); g2d.drawLine((int)_startPosX + 90, (int)_startPosY + 40, (int)_startPosX + 95, (int)_startPosY + 43); //Граница стрелы крана g2d.drawPolygon(xValuesBorderCrane, yValuesBorderCrane, 3); } g2d.setPaint(Ship.GetBodyColor()); int xValues[]={(int) _startPosX,(int) _startPosX + 100,(int) _startPosX + 80,(int) _startPosX + 20}; int yValues[]={(int) _startPosY + 30,(int) _startPosY + 30,(int) _startPosY + 60,(int) _startPosY + 60}; g2d.fillPolygon(xValues,yValues,4); g2d.setPaint(Color.BLACK); g2d.drawPolygon(xValues,yValues,4); } }