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); - } }