From a8835362770aed3d20e899765906901cd2eb8365 Mon Sep 17 00:00:00 2001 From: DanilaSm08 Date: Wed, 5 Jun 2024 18:30:25 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=D0=BD=D0=BD=D0=B0=D1=8F=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80?= =?UTF-8?q?=D0=B0=D1=82=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1?= =?UTF-8?q?=D0=BE=D1=82=D0=B0=20=E2=84=961?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/module-info.java | 4 ++ .../{ => Drawnings}/DirectionType.java | 2 +- .../{ => Drawnings}/DrawningCleaningCar.java | 47 ++++++++++--------- .../DrawningCleaningCarWheel.java | 5 +- .../{ => Entities}/EntityCleaningCar.java | 46 +++--------------- .../projectcleaningcar/FormCleaningCar.java | 28 +++++------ .../projectcleaningcar/WheelCount.java | 5 -- 7 files changed, 50 insertions(+), 87 deletions(-) rename ProjectCleaningCar/src/main/java/org/projectcleaningcar/projectcleaningcar/{ => Drawnings}/DirectionType.java (53%) rename ProjectCleaningCar/src/main/java/org/projectcleaningcar/projectcleaningcar/{ => Drawnings}/DrawningCleaningCar.java (87%) rename ProjectCleaningCar/src/main/java/org/projectcleaningcar/projectcleaningcar/{ => Drawnings}/DrawningCleaningCarWheel.java (83%) rename ProjectCleaningCar/src/main/java/org/projectcleaningcar/projectcleaningcar/{ => Entities}/EntityCleaningCar.java (70%) diff --git a/ProjectCleaningCar/src/main/java/module-info.java b/ProjectCleaningCar/src/main/java/module-info.java index d6792f9..8d0e156 100644 --- a/ProjectCleaningCar/src/main/java/module-info.java +++ b/ProjectCleaningCar/src/main/java/module-info.java @@ -6,4 +6,8 @@ module org.projectcleaningcar.projectcleaningcar { opens org.projectcleaningcar.projectcleaningcar to javafx.fxml; exports org.projectcleaningcar.projectcleaningcar; + exports org.projectcleaningcar.projectcleaningcar.Entities; + opens org.projectcleaningcar.projectcleaningcar.Entities to javafx.fxml; + exports org.projectcleaningcar.projectcleaningcar.Drawnings; + opens org.projectcleaningcar.projectcleaningcar.Drawnings to javafx.fxml; } \ No newline at end of file diff --git a/ProjectCleaningCar/src/main/java/org/projectcleaningcar/projectcleaningcar/DirectionType.java b/ProjectCleaningCar/src/main/java/org/projectcleaningcar/projectcleaningcar/Drawnings/DirectionType.java similarity index 53% rename from ProjectCleaningCar/src/main/java/org/projectcleaningcar/projectcleaningcar/DirectionType.java rename to ProjectCleaningCar/src/main/java/org/projectcleaningcar/projectcleaningcar/Drawnings/DirectionType.java index 577a266..0bd1240 100644 --- a/ProjectCleaningCar/src/main/java/org/projectcleaningcar/projectcleaningcar/DirectionType.java +++ b/ProjectCleaningCar/src/main/java/org/projectcleaningcar/projectcleaningcar/Drawnings/DirectionType.java @@ -1,4 +1,4 @@ -package org.projectcleaningcar.projectcleaningcar; +package org.projectcleaningcar.projectcleaningcar.Drawnings; public enum DirectionType { Up, diff --git a/ProjectCleaningCar/src/main/java/org/projectcleaningcar/projectcleaningcar/DrawningCleaningCar.java b/ProjectCleaningCar/src/main/java/org/projectcleaningcar/projectcleaningcar/Drawnings/DrawningCleaningCar.java similarity index 87% rename from ProjectCleaningCar/src/main/java/org/projectcleaningcar/projectcleaningcar/DrawningCleaningCar.java rename to ProjectCleaningCar/src/main/java/org/projectcleaningcar/projectcleaningcar/Drawnings/DrawningCleaningCar.java index 7593f2c..bd5041a 100644 --- a/ProjectCleaningCar/src/main/java/org/projectcleaningcar/projectcleaningcar/DrawningCleaningCar.java +++ b/ProjectCleaningCar/src/main/java/org/projectcleaningcar/projectcleaningcar/Drawnings/DrawningCleaningCar.java @@ -1,21 +1,19 @@ -package org.projectcleaningcar.projectcleaningcar; +package org.projectcleaningcar.projectcleaningcar.Drawnings; import javafx.scene.canvas.GraphicsContext; import javafx.scene.paint.Color; +import org.projectcleaningcar.projectcleaningcar.Entities.EntityCleaningCar; import java.util.Random; /** * Класс, отвечающий за прорисовку и перемещение объекта-сущности */ -public class DrawningCleaningCar { +public class DrawningCleaningCar{ /** * Класс-сущность */ private EntityCleaningCar entityCleaningCar; - public EntityCleaningCar getEntityCleaningCar() { - return entityCleaningCar; - } private DrawningCleaningCarWheel drawningCleaningCarWheel; /** @@ -31,7 +29,7 @@ public class DrawningCleaningCar { /** * Левая координата прорисовки автомобиля */ - private int startPosX ; + private int startPosX; /** * Верхняя координата прорисовки автомобиля @@ -112,30 +110,33 @@ public class DrawningCleaningCar { */ public boolean moveTransport(DirectionType direction) { double step = entityCleaningCar.getStep(); - switch (direction) { - case Left: + return switch (direction) { + case Left -> { if (startPosX - step > 0) { - startPosX -= step; + startPosX -= (int) step; } - return true; - case Up: + yield true; + } + case Up -> { if (startPosY - step > 0) { - startPosY -= step; + startPosY -= (int) step; } - return true; - case Right: + yield true; + } + case Right -> { if (startPosX + drawingCleaningCarWidth + step < pictureWidth) { - startPosX += step; + startPosX += (int) step; } - return true; - case Down: + yield true; + } + case Down -> { if (startPosY + drawingCleaningCarHeight + step < pictureHeight) { - startPosY += step; + startPosY += (int) step; } - return true; - default: - return false; - } + yield true; + } + default -> false; + }; } /** @@ -185,7 +186,7 @@ public class DrawningCleaningCar { gc.strokePolygon(xPoints, yPoints, 3); } - drawningCleaningCarWheel.drawCleaningCarWheel(gc, Color.valueOf("black"), startPosX, startPosY); + drawningCleaningCarWheel.drawCleaningCarWheel(gc, startPosX, startPosY); } } diff --git a/ProjectCleaningCar/src/main/java/org/projectcleaningcar/projectcleaningcar/DrawningCleaningCarWheel.java b/ProjectCleaningCar/src/main/java/org/projectcleaningcar/projectcleaningcar/Drawnings/DrawningCleaningCarWheel.java similarity index 83% rename from ProjectCleaningCar/src/main/java/org/projectcleaningcar/projectcleaningcar/DrawningCleaningCarWheel.java rename to ProjectCleaningCar/src/main/java/org/projectcleaningcar/projectcleaningcar/Drawnings/DrawningCleaningCarWheel.java index 8f1eb79..240c866 100644 --- a/ProjectCleaningCar/src/main/java/org/projectcleaningcar/projectcleaningcar/DrawningCleaningCarWheel.java +++ b/ProjectCleaningCar/src/main/java/org/projectcleaningcar/projectcleaningcar/Drawnings/DrawningCleaningCarWheel.java @@ -1,6 +1,7 @@ -package org.projectcleaningcar.projectcleaningcar; +package org.projectcleaningcar.projectcleaningcar.Drawnings; import javafx.scene.canvas.GraphicsContext; import javafx.scene.paint.Color; +import org.projectcleaningcar.projectcleaningcar.WheelCount; public class DrawningCleaningCarWheel { private WheelCount wheelCount; @@ -14,7 +15,7 @@ public class DrawningCleaningCarWheel { } } - public void drawCleaningCarWheel(GraphicsContext gc, Color color, int startPosX, int startPosY) { + public void drawCleaningCarWheel(GraphicsContext gc, int startPosX, int startPosY) { gc.setFill(Color.BLACK); int wheels = wheelCount.getEnumNumber(); switch(wheels) { diff --git a/ProjectCleaningCar/src/main/java/org/projectcleaningcar/projectcleaningcar/EntityCleaningCar.java b/ProjectCleaningCar/src/main/java/org/projectcleaningcar/projectcleaningcar/Entities/EntityCleaningCar.java similarity index 70% rename from ProjectCleaningCar/src/main/java/org/projectcleaningcar/projectcleaningcar/EntityCleaningCar.java rename to ProjectCleaningCar/src/main/java/org/projectcleaningcar/projectcleaningcar/Entities/EntityCleaningCar.java index 9a84300..48dc82a 100644 --- a/ProjectCleaningCar/src/main/java/org/projectcleaningcar/projectcleaningcar/EntityCleaningCar.java +++ b/ProjectCleaningCar/src/main/java/org/projectcleaningcar/projectcleaningcar/Entities/EntityCleaningCar.java @@ -1,4 +1,4 @@ -package org.projectcleaningcar.projectcleaningcar; +package org.projectcleaningcar.projectcleaningcar.Entities; import javafx.scene.paint.Color; /** @@ -8,32 +8,32 @@ public class EntityCleaningCar { /** * Скорость */ - private int speed; + private final int speed; /** * Вес */ - private double weight; + private final double weight; /** * Основной цвет */ - private Color bodyColor; + private final Color bodyColor; /** * Дополнительный цвет (для опциональных элементов) */ - private Color additionalColor; + private final Color additionalColor; /** * Признак (опция) наличия бака под воду */ - private boolean waterTank; + private final boolean waterTank; /** * Признак (опция) наличия подметательной щётки */ - private boolean sweepingBrush; + private final boolean sweepingBrush; /** * Конструктор для инициализации полей объекта-класса подметально-уборочной машины @@ -64,51 +64,19 @@ public class EntityCleaningCar { // Геттеры и сеттеры - public int getSpeed() { - return speed; - } - - public void setSpeed(int speed) { - this.speed = speed; - } - - public double getWeight() { - return weight; - } - - public void setWeight(double weight) { - this.weight = weight; - } - public Color getBodyColor() { return bodyColor; } - public void setBodyColor(Color bodyColor) { - this.bodyColor = bodyColor; - } - public Color getAdditionalColor() { return additionalColor; } - public void setAdditionalColor(Color additionalColor) { - this.additionalColor = additionalColor; - } - public boolean isWaterTank() { return waterTank; } - public void setWaterTank(boolean waterTank) { - this.waterTank = waterTank; - } - public boolean isSweepingBrush() { return sweepingBrush; } - - public void setSweepingBrush(boolean sweepingBrush) { - this.sweepingBrush = sweepingBrush; - } } diff --git a/ProjectCleaningCar/src/main/java/org/projectcleaningcar/projectcleaningcar/FormCleaningCar.java b/ProjectCleaningCar/src/main/java/org/projectcleaningcar/projectcleaningcar/FormCleaningCar.java index d7f6ac5..87de199 100644 --- a/ProjectCleaningCar/src/main/java/org/projectcleaningcar/projectcleaningcar/FormCleaningCar.java +++ b/ProjectCleaningCar/src/main/java/org/projectcleaningcar/projectcleaningcar/FormCleaningCar.java @@ -10,6 +10,9 @@ import javafx.scene.paint.Color; import javafx.scene.control.Button; import javafx.scene.canvas.Canvas; import javafx.scene.canvas.GraphicsContext; +import org.projectcleaningcar.projectcleaningcar.Drawnings.DirectionType; +import org.projectcleaningcar.projectcleaningcar.Drawnings.DrawningCleaningCar; + import java.util.Random; import java.io.IOException; @@ -47,7 +50,7 @@ public class FormCleaningCar extends Application { } @FXML - private void buttonCreateCleaningCar(ActionEvent event) { + private void buttonCreateCleaningCar() { Random random = new Random(); _drawningCleaningCar = new DrawningCleaningCar(); _drawningCleaningCar.init(random.nextInt(300 - 100 + 1) + 100, @@ -66,22 +69,13 @@ public class FormCleaningCar extends Application { if (_drawningCleaningCar == null) return; if (canvasCleaningCar.getWidth() == 0 || canvasCleaningCar.getHeight() == 0) return; String name = ((Button) event.getSource()).getId(); - boolean result = false; - - switch (name){ - case "Up": - result = _drawningCleaningCar.moveTransport(DirectionType.Up); - break; - case "Down": - result = _drawningCleaningCar.moveTransport(DirectionType.Down); - break; - case "Left": - result = _drawningCleaningCar.moveTransport(DirectionType.Left); - break; - case "Right": - result = _drawningCleaningCar.moveTransport(DirectionType.Right); - break; - } + boolean result = switch (name) { + case "Up" -> _drawningCleaningCar.moveTransport(DirectionType.Up); + case "Down" -> _drawningCleaningCar.moveTransport(DirectionType.Down); + case "Left" -> _drawningCleaningCar.moveTransport(DirectionType.Left); + case "Right" -> _drawningCleaningCar.moveTransport(DirectionType.Right); + default -> false; + }; if(result) draw(); } diff --git a/ProjectCleaningCar/src/main/java/org/projectcleaningcar/projectcleaningcar/WheelCount.java b/ProjectCleaningCar/src/main/java/org/projectcleaningcar/projectcleaningcar/WheelCount.java index 8c47a96..d9f132e 100644 --- a/ProjectCleaningCar/src/main/java/org/projectcleaningcar/projectcleaningcar/WheelCount.java +++ b/ProjectCleaningCar/src/main/java/org/projectcleaningcar/projectcleaningcar/WheelCount.java @@ -14,10 +14,5 @@ public enum WheelCount { public int getEnumNumber() { return enumNumber; } - - @Override - public String toString() { - return String.valueOf(enumNumber); - } }