diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..002da1d --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +Main.java \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/resources/down-arrow.png b/resources/down-arrow.png new file mode 100644 index 0000000..9d67143 Binary files /dev/null and b/resources/down-arrow.png differ diff --git a/resources/left-arrow.png b/resources/left-arrow.png new file mode 100644 index 0000000..046470d Binary files /dev/null and b/resources/left-arrow.png differ diff --git a/resources/right-arrow.png b/resources/right-arrow.png new file mode 100644 index 0000000..fac4c96 Binary files /dev/null and b/resources/right-arrow.png differ diff --git a/resources/upper-arrow.png b/resources/upper-arrow.png new file mode 100644 index 0000000..0bc323d Binary files /dev/null and b/resources/upper-arrow.png differ diff --git a/src/DrawingShip.java b/src/DrawingShip.java new file mode 100644 index 0000000..cef2fd8 --- /dev/null +++ b/src/DrawingShip.java @@ -0,0 +1,120 @@ + +import java.awt.*; + +public class DrawingShip { + private EntityShip entityShip; + public EntityShip GetEntityShip(){ + return entityShip; + } + private void SetEntityShip(EntityShip entityShip){ + this.entityShip = entityShip; + } + private DrawingDecks drawingDecks; + public DrawingDecks GetDrawingDecks(){ + return drawingDecks; + } + private void SetDrawingDecks( DrawingDecks drawingDecks){ + this.drawingDecks = drawingDecks; + } + private int _pictureWidth; + private int _pictureHeight; + private int _startPosX; + private int _startPosY; + private final int _shipWidth = 185; + private final int _shipHeight = 180; + public boolean Init(int speed, double weight, Color bodyColor, Color addColor, boolean pipes, boolean section, int width, int height, int countDecks){ + if (width < _shipWidth || height <_shipHeight){ + return false; + } + _pictureWidth = width; + _pictureHeight = height; + entityShip = new EntityShip(); + entityShip.Init(speed, weight, bodyColor, addColor, pipes, section); + drawingDecks = new DrawingDecks(); + drawingDecks.SetCountDecks(countDecks); + return true; + } + public void SetPosition(int x, int y){ + if (x < 0 || x + _shipWidth > _pictureWidth){ + x = 20; + } + if (y < 0 || y + _shipHeight > _pictureHeight){ + y = 20; + } + _startPosX = x; + _startPosY = y; + } + public void MoveTransport(Direction direction){ + if (entityShip == null){ + return; + } + switch (direction){ + case Left: + System.out.println(_startPosX + " " + entityShip.GetStep() + " " + _shipWidth + " " + (_startPosX + entityShip.GetStep() + _shipWidth) + " " + _pictureWidth); + if (_startPosX - entityShip.GetStep() > 0){ + _startPosX -= (int)entityShip.GetStep(); + } + break; + case Up: + System.out.println(_startPosY + " " + entityShip.GetStep() + " " + (_startPosY + entityShip.GetStep()) + " " + _pictureHeight); + if (_startPosY - entityShip.GetStep() > 0){ + _startPosY -= (int)entityShip.GetStep(); + } + break; + case Right: + System.out.println(_startPosX + " " + entityShip.GetStep() + " " + _shipWidth + " " + (_startPosX + entityShip.GetStep() + _shipWidth) + " " + _pictureWidth); + if (_startPosX + entityShip.GetStep() + _shipWidth < _pictureWidth){ + _startPosX += (int)entityShip.GetStep(); + } + break; + case Down: + System.out.println(_startPosY + " " + entityShip.GetStep() + " " + (_startPosY + entityShip.GetStep()) + " " + _pictureHeight); + if (_startPosY + entityShip.GetStep() + _shipHeight < _pictureHeight){ + _startPosY += (int)entityShip.GetStep(); + } + break; + } + } + + public void DrawTransport(Graphics g) { + if (entityShip == null || drawingDecks == null) { + System.out.println("Error"); + return; + } + //корпус + int[] XPoints = {_startPosX, _startPosX + 180, _startPosX + 140, _startPosX + 40, _startPosX}; + int[] YPoints = {_startPosY + 110, _startPosY + 110, _startPosY + 185, _startPosY + 185, _startPosY + 110}; + + int nPoints = 5; + g.setColor(entityShip.GetBodyColor()); + g.fillPolygon(XPoints, YPoints, nPoints); + g.setColor(Color.black); + g.drawPolygon(XPoints, YPoints, nPoints); + + //якорь + g.drawLine(_startPosX + 50, _startPosY + 130, _startPosX + 50, _startPosY + 150); + g.drawLine(_startPosX + 40, _startPosY + 140, _startPosX + 60, _startPosY + 140); + g.drawLine(_startPosX + 45, _startPosY + 150, _startPosX + 55, _startPosY + 150); + + //трубы + if (entityShip.GetPipes()) { + g.setColor(entityShip.GetAddColor()); + g.fillRect(_startPosX + 55, _startPosY, 25, 80); + g.fillRect(_startPosX + 90, _startPosY + 20, 25, 60); + g.setColor(Color.black); + g.drawRect(_startPosX + 55, _startPosY, 25, 80); + g.drawRect(_startPosX + 90, _startPosY + 20, 25, 60); + } + + //топливный отсек + if (entityShip.GetSection()) { + g.setColor(Color.gray); + g.fillOval(_startPosX + 130, _startPosY + 130, 20, 20); + g.setColor(Color.black); + g.drawOval(_startPosX + 130, _startPosY + 130, 20, 20); + } + + //палуба + drawingDecks.DrawingDecks(_startPosX, _startPosY, entityShip.GetBodyColor(), g); + } +} \ No newline at end of file