From 1578c07887232c12d0f0168c404c9e2f629188a5 Mon Sep 17 00:00:00 2001 From: ShipilovNikita Date: Mon, 19 Feb 2024 11:24:47 +0400 Subject: [PATCH] =?UTF-8?q?=D0=92=D0=BD=D0=B5=D1=81=20=D0=BF=D0=BE=D0=BF?= =?UTF-8?q?=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20=D0=B2=20=D1=81=D1=82=D1=80?= =?UTF-8?q?=D1=83=D0=BA=D1=82=D1=83=D1=80=D1=83=20=D0=BA=D0=BB=D0=B0=D1=81?= =?UTF-8?q?=D1=81=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Seaplane/src/DrawingSeaplane.java | 87 +++++++++++----------- Seaplane/src/DrawingSeaplanePortholes.java | 15 ++-- 2 files changed, 50 insertions(+), 52 deletions(-) diff --git a/Seaplane/src/DrawingSeaplane.java b/Seaplane/src/DrawingSeaplane.java index 6d59d11..d694032 100644 --- a/Seaplane/src/DrawingSeaplane.java +++ b/Seaplane/src/DrawingSeaplane.java @@ -9,7 +9,6 @@ public class DrawingSeaplane { private Integer _startPosY; private final int drawingSeaplaneWidth = 190; private final int drawingSeaplaneHeight = 90; - private final int drawingKeelHeight = 35; private DrawingSeaplanePortholes _drawingSeaplanePortholes; public EntitySeaplane EntitySeaplane() { return entitySeaplane; @@ -24,7 +23,7 @@ public class DrawingSeaplane { _drawingSeaplanePortholes = new DrawingSeaplanePortholes(entitySeaplane); Random random = new Random(); int paddlesCount = random.nextInt(1,4); - _drawingSeaplanePortholes.setEnumNumber(paddlesCount * 10); + _drawingSeaplanePortholes.setPortholesCount(paddlesCount * 10); } public void setPictureSize(int width, int height) { @@ -43,8 +42,8 @@ public class DrawingSeaplane { x = pictureWidth - drawingSeaplaneWidth - drawingSeaplaneWidth; } - if (y - drawingKeelHeight < 0) { - y = drawingKeelHeight; + if (y < 0) { + y = 0; } else if (y - drawingSeaplaneHeight >= pictureHeight) { y = pictureHeight - drawingSeaplaneHeight - drawingSeaplaneHeight; } @@ -66,7 +65,7 @@ public class DrawingSeaplane { yield true; } case Up -> { - if (_startPosY - drawingKeelHeight - entitySeaplane.getStep() >= 0) { + if (_startPosY - entitySeaplane.getStep() >= 0) { _startPosY -= (int) entitySeaplane.getStep(); } yield true; @@ -78,7 +77,7 @@ public class DrawingSeaplane { yield true; } case Down -> { - if (_startPosY + entitySeaplane.getStep() <= pictureHeight - drawingSeaplaneHeight + drawingKeelHeight) { + if (_startPosY + entitySeaplane.getStep() <= pictureHeight - drawingSeaplaneHeight) { _startPosY += (int) entitySeaplane.getStep(); } yield true; @@ -95,49 +94,49 @@ public class DrawingSeaplane { Graphics2D g2d = (Graphics2D) g; g2d.setColor(Color.BLACK); // Отрисовка корпуса - g2d.drawOval(_startPosX, _startPosY + 4, 20, 20); - g2d.drawOval(_startPosX, _startPosY + 14, 20, 20); - g2d.drawRect(_startPosX, _startPosY + 15, 10, 10); - g2d.drawRect(_startPosX + 170, _startPosY + 15, 10, 10); - g2d.drawRect(_startPosX + 10, _startPosY + 4, 160, 30); + g2d.drawOval(_startPosX, _startPosY + 34, 20, 20); + g2d.drawOval(_startPosX, _startPosY + 44, 20, 20); + g2d.drawRect(_startPosX, _startPosY + 45, 10, 10); + g2d.drawRect(_startPosX + 170, _startPosY + 45, 10, 10); + g2d.drawRect(_startPosX + 10, _startPosY + 34, 160, 30); // Отрисовка верхней части int[] xPointsTop = {_startPosX + 170, _startPosX + 170, _startPosX + 190}; - int[] yPointsTop = {_startPosY, _startPosY + 20, _startPosY + 20}; + int[] yPointsTop = {_startPosY+30, _startPosY + 50, _startPosY + 50}; g2d.drawPolygon(xPointsTop, yPointsTop, 3); // Отрисовка нижней части int[] xPointsBottom = {_startPosX + 170, _startPosX + 170, _startPosX + 190}; - int[] yPointsBottom = {_startPosY + 40, _startPosY + 20, _startPosY + 20}; + int[] yPointsBottom = {_startPosY + 70, _startPosY + 50, _startPosY + 50}; g2d.drawPolygon(xPointsBottom, yPointsBottom, 3); // Отрисовка киля int[] xPointsKeel = {_startPosX + 10, _startPosX + 10, _startPosX + 50}; - int[] yPointsKeel = {_startPosY - 30, _startPosY + 5, _startPosY + 5}; + int[] yPointsKeel = {_startPosY, _startPosY + 35, _startPosY + 35}; g2d.drawPolygon(xPointsKeel, yPointsKeel, 3); if (!entitySeaplane.getFloats()) { // Рисуем переднее шасси с одним колесом - g2d.drawOval( _startPosX + 140, _startPosY + 45, 10, 10); + g2d.drawOval( _startPosX + 140, _startPosY + 75, 10, 10); // Рисуем задние шасси с двумя колесами - g2d.drawOval( _startPosX + 20, _startPosY + 45, 10, 10); - g2d.drawOval( _startPosX + 30, _startPosY + 45, 10, 10); + g2d.drawOval( _startPosX + 20, _startPosY + 75, 10, 10); + g2d.drawOval( _startPosX + 30, _startPosY + 75, 10, 10); // Рисуем ногу переднего шасси - g2d.drawLine( _startPosX + 145, _startPosY + 35, _startPosX + 145, _startPosY + 50); + g2d.drawLine( _startPosX + 145, _startPosY + 75, _startPosX + 145, _startPosY + 50); // Рисуем ноги заднего шасси - g2d.drawLine( _startPosX + 30, _startPosY + 35, _startPosX + 30, _startPosY + 50); + g2d.drawLine( _startPosX + 30, _startPosY + 75, _startPosX + 30, _startPosY + 50); } g2d.setColor(entitySeaplane.getBodyColor()); // Закрашиваем корпус - g2d.fillOval(_startPosX, _startPosY + 4, 20, 20); - g2d.fillOval(_startPosX, _startPosY + 14, 20, 20); - g2d.fillOval(_startPosX, _startPosY + 15, 10, 10); - g2d.fillRect(_startPosX + 10, _startPosY + 4, 160, 30); + g2d.fillOval(_startPosX, _startPosY + 34, 20, 20); + g2d.fillOval(_startPosX, _startPosY + 44, 20, 20); + g2d.fillOval(_startPosX, _startPosY + 45, 10, 10); + g2d.fillRect(_startPosX + 10, _startPosY + 34, 160, 30); g2d.setColor(entitySeaplane.getAdditionalColor()); // Закрашиваем дополнительные элементы @@ -145,43 +144,43 @@ public class DrawingSeaplane { g2d.fillPolygon(xPointsBottom, yPointsBottom, 3); g2d.fillPolygon(xPointsKeel, yPointsKeel, 3); - _drawingSeaplanePortholes.drawSeaplanePortholes(g, Color.CYAN, _startPosX, _startPosY); + _drawingSeaplanePortholes.drawSeaplanePortholes(g, Color.CYAN, _startPosX + 10, _startPosY + 41); g2d.setColor(Color.BLACK); // Рисуем триммера - g2d.drawOval( _startPosX, _startPosY, 10, 10); - g2d.drawOval( _startPosX+30, _startPosY, 10, 10); - g2d.drawRect( _startPosX+5, _startPosY, 30, 10); + g2d.drawOval( _startPosX, _startPosY+30, 10, 10); + g2d.drawOval( _startPosX+30, _startPosY+30, 10, 10); + g2d.drawRect( _startPosX+5, _startPosY+30, 30, 10); // Рисуем крыло - g2d.drawOval( _startPosX + 70, _startPosY + 15, 6, 6); - g2d.drawOval( _startPosX + 130, _startPosY + 15, 6, 6); - g2d.drawRect( _startPosX + 75, _startPosY + 15, 60, 6); + g2d.drawOval( _startPosX + 70, _startPosY + 45, 6, 6); + g2d.drawOval( _startPosX + 130, _startPosY + 45, 6, 6); + g2d.drawRect( _startPosX + 75, _startPosY + 45, 60, 6); // Закрашиваем триммера - g2d.fillOval( _startPosX, _startPosY, 10, 10); - g2d.fillOval( _startPosX+30, _startPosY, 10, 10); - g2d.fillRect( _startPosX+5, _startPosY, 30, 10); + g2d.fillOval( _startPosX, _startPosY+30, 10, 10); + g2d.fillOval( _startPosX+30, _startPosY+30, 10, 10); + g2d.fillRect( _startPosX+5, _startPosY+30, 30, 10); // Закрашиваем крыло - g2d.fillOval( _startPosX + 70, _startPosY + 15, 6, 6); - g2d.fillOval( _startPosX + 130, _startPosY + 15, 6, 6); - g2d.fillRect( _startPosX + 75, _startPosY + 15, 60, 6); + g2d.fillOval( _startPosX + 70, _startPosY + 45, 6, 6); + g2d.fillOval( _startPosX + 130, _startPosY + 45, 6, 6); + g2d.fillRect( _startPosX + 75, _startPosY + 45, 60, 6); // Поплавки if (entitySeaplane.getFloats()) { - g2d.drawLine(_startPosX + 125, _startPosY + 35, _startPosX + 125, _startPosY + 50); - g2d.drawLine(_startPosX + 50, _startPosY + 35, _startPosX + 50, _startPosY + 50); - g2d.fillOval(_startPosX + 40, _startPosY + 45, 10, 10); - g2d.fillOval(_startPosX + 125, _startPosY + 45, 10, 10); - g2d.fillRect(_startPosX + 45, _startPosY + 45, 85, 10); + g2d.drawLine(_startPosX + 125, _startPosY + 65, _startPosX + 125, _startPosY + 80); + g2d.drawLine(_startPosX + 50, _startPosY + 65, _startPosX + 50, _startPosY + 80); + g2d.fillOval(_startPosX + 40, _startPosY + 75, 10, 10); + g2d.fillOval(_startPosX + 125, _startPosY + 75, 10, 10); + g2d.fillRect(_startPosX + 45, _startPosY + 75, 85, 10); } g2d.setColor(Color.RED); // Надувная лодка if (entitySeaplane.getInflatableBoat()) { - g2d.fillOval(_startPosX, _startPosY + 30, 8, 8); - g2d.fillOval(_startPosX + 165, _startPosY + 30, 8, 8); - g2d.fillRect(_startPosX + 4, _startPosY + 30, 165, 8); + g2d.fillOval(_startPosX, _startPosY + 60, 8, 8); + g2d.fillOval(_startPosX + 165, _startPosY + 60, 8, 8); + g2d.fillRect(_startPosX + 4, _startPosY + 60, 165, 8); } } } diff --git a/Seaplane/src/DrawingSeaplanePortholes.java b/Seaplane/src/DrawingSeaplanePortholes.java index 60ded54..e6286d6 100644 --- a/Seaplane/src/DrawingSeaplanePortholes.java +++ b/Seaplane/src/DrawingSeaplanePortholes.java @@ -3,11 +3,7 @@ import java.awt.*; public class DrawingSeaplanePortholes { private PortholesCount _portholesCount; private final EntitySeaplane _entitySeaplane; - public DrawingSeaplanePortholes(EntitySeaplane entitySeaplane) { - _entitySeaplane = entitySeaplane; - } - - public void setEnumNumber(int portholesCount) { + public void setPortholesCount(int portholesCount) { for (PortholesCount value : PortholesCount.values()) { if (value.enumNumber == portholesCount) { _portholesCount = value; @@ -15,6 +11,9 @@ public class DrawingSeaplanePortholes { } } } + public DrawingSeaplanePortholes(EntitySeaplane entitySeaplane) { + _entitySeaplane = entitySeaplane; + } public void drawSeaplanePortholes(Graphics g, Color color, float startPosX, float startPosY) { Graphics2D g2d = (Graphics2D) g; @@ -24,13 +23,13 @@ public class DrawingSeaplanePortholes { for (int i = 0; i < _portholesCount.enumNumber; i++) { g2d.setColor(color); int posX = (int)(startPosX + i * distanceBetweenPortholes); - drawPortholeBundle(g2d, posX, (int)startPosY + 5); + drawPortholeBundle(g2d, posX, (int)startPosY); } } private void drawPortholeBundle(Graphics2D g2d, int posX, int posY) { - g2d.fillOval(posX + 10, posY + 6, 5, 5); // Рисуем иллюминатор + g2d.fillOval(posX, posY, 5, 5); // Рисуем иллюминатор g2d.setColor(Color.BLACK); - g2d.drawOval(posX + 10, posY + 6, 5, 5); // Рисуем границу иллюминатора + g2d.drawOval(posX, posY, 5, 5); // Рисуем границу иллюминатора } }