diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/DoubleDeckerBus/pom.xml b/DoubleDeckerBus/pom.xml
new file mode 100644
index 0000000..62d9a1d
--- /dev/null
+++ b/DoubleDeckerBus/pom.xml
@@ -0,0 +1,86 @@
+
+
+ 4.0.0
+
+ com.example
+ DoubleDeckerBus
+ 1.0-SNAPSHOT
+ DoubleDeckerBus
+
+
+ UTF-8
+ 5.8.2
+
+
+
+
+ org.openjfx
+ javafx-controls
+ 18
+
+
+ org.openjfx
+ javafx-fxml
+ 18
+
+
+ org.controlsfx
+ controlsfx
+ 11.1.1
+
+
+ org.kordamp.bootstrapfx
+ bootstrapfx-core
+ 0.4.0
+
+
+ org.junit.jupiter
+ junit-jupiter-api
+ ${junit.version}
+ test
+
+
+ org.junit.jupiter
+ junit-jupiter-engine
+ ${junit.version}
+ test
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.10.1
+
+
+ 18
+
+
+
+ org.openjfx
+ javafx-maven-plugin
+ 0.0.8
+
+
+
+ default-cli
+
+ com.example.doubledeckerbus/com.example.doubledeckerbus.Form
+
+ app
+ app
+ app
+ true
+ true
+ true
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/ControllerBus.java b/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/ControllerBus.java
new file mode 100644
index 0000000..ada3280
--- /dev/null
+++ b/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/ControllerBus.java
@@ -0,0 +1,105 @@
+package com.example.doubledeckerbus;
+
+import javafx.beans.InvalidationListener;
+import javafx.collections.FXCollections;
+import javafx.collections.ObservableList;
+import javafx.event.ActionEvent;
+import javafx.fxml.FXML;
+import javafx.scene.canvas.Canvas;
+import javafx.scene.canvas.GraphicsContext;
+import javafx.scene.control.Button;
+import javafx.scene.control.ChoiceBox;
+import javafx.scene.control.Label;
+import javafx.scene.layout.AnchorPane;
+import javafx.scene.paint.Color;
+
+import java.util.Random;
+
+public class ControllerBus {
+
+ private DrawingBus _bus;
+ ObservableList countOfDoors = FXCollections.observableArrayList(3, 4, 5);
+ @FXML
+ private Button buttonCreate;
+
+ @FXML
+ private Button buttonDown;
+
+ @FXML
+ private Button buttonLeft;
+
+ @FXML
+ private Button buttonRight;
+
+ @FXML
+ private Button buttonUp;
+
+ @FXML
+ private Canvas canvasBus;
+
+ @FXML
+ private AnchorPane pictureBoxBus;
+
+ @FXML
+ private Label statusColor;
+
+ @FXML
+ private Label statusSpeed;
+
+ @FXML
+ private Label statusWeight;
+
+ @FXML
+ private ChoiceBox choiceDoors;
+
+ @FXML
+ void ButtonCreate_Click(ActionEvent event) {
+ pictureBoxBus.widthProperty().addListener(listener);
+ pictureBoxBus.heightProperty().addListener(listener);
+
+ Random rnd = new Random();
+ _bus = new DrawingBus();
+ _bus.Init(rnd.nextInt(100, 300), rnd.nextFloat(1000, 2000),
+ Color.rgb(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)), choiceDoors.getValue());
+ _bus.SetPosition(rnd.nextInt(10, 100), rnd.nextInt(10, 100), (int) pictureBoxBus.getWidth(), (int) pictureBoxBus.getHeight());
+ statusSpeed.setText("Скорость: %s".formatted(_bus.Bus.Speed));
+ statusWeight.setText("Вес: %s".formatted(_bus.Bus.Weight));
+ statusColor.setText("Цвет: %s".formatted(_bus.Bus.BodyColor));
+ BorderChanged();
+ }
+
+ @FXML
+ void ButtonMove_Click(ActionEvent event) {
+ if (_bus == null) return;
+ String name = ((Button) event.getSource()).getId();
+ switch (name) {
+ case "buttonUp" -> _bus.MoveTransport(Direction.Up);
+ case "buttonDown" -> _bus.MoveTransport(Direction.Down);
+ case "buttonLeft" -> _bus.MoveTransport(Direction.Left);
+ case "buttonRight" -> _bus.MoveTransport(Direction.Right);
+ }
+ Draw();
+ }
+
+ @FXML
+ public void initialize() {
+ choiceDoors.setItems(countOfDoors);
+ choiceDoors.setValue(3);
+ }
+
+ InvalidationListener listener = o -> BorderChanged();
+
+ private void Draw()
+ {
+ GraphicsContext gc = canvasBus.getGraphicsContext2D();
+ _bus.DrawTransport(gc);
+ }
+
+ void BorderChanged() {
+ canvasBus.setWidth(pictureBoxBus.getWidth());
+ canvasBus.setHeight(pictureBoxBus.getHeight());
+ _bus.ChangeBorders((int) pictureBoxBus.getWidth(), (int) pictureBoxBus.getHeight());
+ Draw();
+ }
+
+}
diff --git a/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/CountOfDoors.java b/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/CountOfDoors.java
new file mode 100644
index 0000000..a6fd2b2
--- /dev/null
+++ b/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/CountOfDoors.java
@@ -0,0 +1,18 @@
+package com.example.doubledeckerbus;
+
+public enum CountOfDoors {
+
+ ThreeDoors(3),
+ FourDoors(4),
+ FiveDoors(5);
+
+ private final int id;
+ CountOfDoors(int value){
+ id = value;
+ }
+
+ public int getId() {
+ return id;
+ }
+
+}
diff --git a/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/Direction.java b/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/Direction.java
new file mode 100644
index 0000000..66ea455
--- /dev/null
+++ b/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/Direction.java
@@ -0,0 +1,11 @@
+package com.example.doubledeckerbus;
+
+public enum Direction {
+ Up(1),
+ Down(2),
+ Left(3),
+ Right(4);
+ Direction(int value){}
+
+}
+
diff --git a/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/DrawingBus.java b/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/DrawingBus.java
new file mode 100644
index 0000000..d81f6d0
--- /dev/null
+++ b/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/DrawingBus.java
@@ -0,0 +1,124 @@
+package com.example.doubledeckerbus;
+
+import javafx.scene.canvas.GraphicsContext;
+import javafx.scene.paint.Color;
+
+public class DrawingBus {
+ public EntityBus Bus;
+
+ public DrawingDoors Doors;
+
+ public EntityBus getBus() {
+ return Bus;
+ }
+
+ private static final int _null = -1000;
+ private float _startPosX;
+ private float _startPosY;
+ private int _pictureWidth;
+ private int _pictureHeight;
+ private static final int _busWidth = 100;
+ private static final int _busHeight = 50;
+
+ public void Init(int speed, float weight, Color bodyColor, int countOfDoors) {
+ Bus = new EntityBus();
+ Bus.Init(speed, weight, bodyColor);
+ Doors = new DrawingDoors();
+ Doors.setCountOfDoors(countOfDoors);
+ }
+
+ public void SetPosition(int x, int y, int width, int height) {
+ if (x < 0 || y < 0) return;
+
+ if (_pictureWidth <= _busWidth || _pictureHeight <= _busHeight) {
+ _pictureWidth = _null;
+ _pictureHeight = _null;
+ return;
+ }
+ _startPosX = x;
+ _startPosY = y;
+ _pictureWidth = width;
+ _pictureHeight = height;
+ }
+
+ public void MoveTransport(Direction direction)
+ {
+ if (_pictureWidth == _null || _pictureHeight == _null)
+ {
+ return;
+ }
+
+ switch (direction)
+ {
+ case Right:
+ if (_startPosX + _busWidth + Bus.Step < _pictureWidth) {
+ _startPosX += Bus.Step;
+ }
+ break;
+ case Left:
+ if (_startPosX - Bus.Step >= 0) {
+ _startPosX -= Bus.Step;
+ }
+ break;
+ case Up:
+ if (_startPosY - Bus.Step >= 0) {
+ _startPosY -= Bus.Step;
+ }
+ break;
+ case Down:
+ if (_startPosY + _busHeight + Bus.Step < _pictureHeight) {
+ _startPosY += Bus.Step;
+ }
+ break;
+ default:
+ break;
+ }
+ }
+
+ public void DrawTransport(GraphicsContext gc)
+ {
+ if (_startPosX < 0 || _startPosY < 0
+ || _pictureHeight == _null || _pictureWidth == _null)
+ {
+ return;
+ }
+
+ gc.clearRect(0, 0, _pictureWidth, _pictureHeight);
+ gc.setFill(Bus.BodyColor);
+ gc.fillRect(_startPosX, _startPosY + 10, 100, 30);
+
+ //Колеса
+ gc.setFill(Color.BLACK);
+ gc.fillOval(_startPosX + 7, _startPosY + 35, 10, 10);
+ gc.fillOval(_startPosX + 77, _startPosY + 35, 10, 10);
+
+ //окна
+ gc.setFill(Color.BLUE);
+ gc.fillOval(_startPosX + 10, _startPosY + 15, 10, 15);
+ gc.fillOval(_startPosX + 50, _startPosY + 15, 10, 15);
+ gc.fillOval(_startPosX + 70, _startPosY + 15, 10, 15);
+ gc.fillOval(_startPosX + 90, _startPosY + 15, 10, 15);
+
+ //Дверь
+ Doors.DrawDoors(gc, (int)_startPosX, (int)_startPosY);
+ }
+
+ public void ChangeBorders(int width, int height) {
+ _pictureWidth = width;
+ _pictureHeight = height;
+
+ if (_pictureWidth <= _busWidth || _pictureHeight <= _busHeight){
+ _pictureWidth = _null;
+ _pictureHeight = _null;
+ return;
+ }
+
+ if (_startPosX + _busWidth > _pictureWidth) {
+ _startPosX = _pictureWidth - _busWidth;
+
+ }
+ if (_startPosY + _busHeight > _pictureHeight) {
+ _startPosY = _pictureHeight - _busHeight;
+ }
+ }
+}
diff --git a/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/DrawingDoors.java b/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/DrawingDoors.java
new file mode 100644
index 0000000..7c902d7
--- /dev/null
+++ b/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/DrawingDoors.java
@@ -0,0 +1,31 @@
+package com.example.doubledeckerbus;
+
+import javafx.scene.canvas.GraphicsContext;
+import javafx.scene.paint.Color;
+
+public class DrawingDoors {
+ private CountOfDoors _countOfDoors;
+
+ public void DrawDoors(GraphicsContext gc, int _startPosX, int _startPosY) {
+ gc.setFill(Color.BLACK);
+ gc.fillRect(_startPosX, _startPosY + 20, 10, 20);
+ gc.fillRect(_startPosX + 20, _startPosY + 20, 10, 20);
+ gc.fillRect(_startPosX + 40, _startPosY + 20, 10, 20);
+ if (_countOfDoors.getId() >= 4) {
+ gc.fillRect(_startPosX + 60, _startPosY + 20, 10, 20);
+ }
+ if (_countOfDoors.getId() >= 5) {
+ gc.fillRect(_startPosX + 80, _startPosY + 20, 10, 20);
+ }
+ }
+
+ public void setCountOfDoors(int number) {
+ for (CountOfDoors item: CountOfDoors.values()) {
+ if (item.getId() == number) {
+ _countOfDoors = item;
+ return;
+ }
+ }
+
+ }
+}
diff --git a/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/EntityBus.java b/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/EntityBus.java
new file mode 100644
index 0000000..832cff3
--- /dev/null
+++ b/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/EntityBus.java
@@ -0,0 +1,38 @@
+package com.example.doubledeckerbus;
+
+import javafx.scene.paint.Color;
+
+import java.util.Random;
+
+public class EntityBus {
+ public int Speed;
+ public float Weight;
+ public Color BodyColor;
+ public float Step;
+
+ public void Init(int speed, float weight, Color bodyColor)
+ {
+ Random rnd = new Random();
+ Speed = (speed <= 0) ? rnd.nextInt(50, 150): speed;
+ Weight = (weight <= 0) ? rnd.nextFloat(50, 70) : weight;
+ BodyColor = bodyColor;
+ Step = Speed * 100 / Weight;
+ }
+
+ public int getSpeed() {
+ return Speed;
+ }
+
+ public float getWeight() {
+ return Weight;
+ }
+
+ public Color getBodyColor() {
+ return BodyColor;
+ }
+
+ public float getStep() {
+ return Step;
+ }
+
+}
diff --git a/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/Form.java b/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/Form.java
new file mode 100644
index 0000000..1b97591
--- /dev/null
+++ b/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/Form.java
@@ -0,0 +1,23 @@
+package com.example.doubledeckerbus;
+
+import javafx.application.Application;
+import javafx.fxml.FXMLLoader;
+import javafx.scene.Scene;
+import javafx.stage.Stage;
+
+import java.io.IOException;
+
+public class Form extends Application {
+ @Override
+ public void start(Stage stage) throws IOException {
+ FXMLLoader fxmlLoader = new FXMLLoader(Form.class.getResource("hello-view.fxml"));
+ Scene scene = new Scene(fxmlLoader.load());
+ stage.setTitle("DoubleDeckerBus");
+ stage.setScene(scene);
+ stage.show();
+ }
+
+ public static void main(String[] args) {
+ launch();
+ }
+}
\ No newline at end of file
diff --git a/DoubleDeckerBus/src/main/java/module-info.java b/DoubleDeckerBus/src/main/java/module-info.java
new file mode 100644
index 0000000..3e43a04
--- /dev/null
+++ b/DoubleDeckerBus/src/main/java/module-info.java
@@ -0,0 +1,10 @@
+module com.example.doubledeckerbus {
+ requires javafx.controls;
+ requires javafx.fxml;
+
+ requires org.controlsfx.controls;
+ requires org.kordamp.bootstrapfx.core;
+
+ opens com.example.doubledeckerbus to javafx.fxml;
+ exports com.example.doubledeckerbus;
+}
\ No newline at end of file
diff --git a/DoubleDeckerBus/src/main/resources/com/example/doubledeckerbus/hello-view.fxml b/DoubleDeckerBus/src/main/resources/com/example/doubledeckerbus/hello-view.fxml
new file mode 100644
index 0000000..cb431c8
--- /dev/null
+++ b/DoubleDeckerBus/src/main/resources/com/example/doubledeckerbus/hello-view.fxml
@@ -0,0 +1,76 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/DoubleDeckerBus/src/main/resources/com/example/doubledeckerbus/images/DownArrow.png b/DoubleDeckerBus/src/main/resources/com/example/doubledeckerbus/images/DownArrow.png
new file mode 100644
index 0000000..ec660ba
Binary files /dev/null and b/DoubleDeckerBus/src/main/resources/com/example/doubledeckerbus/images/DownArrow.png differ
diff --git a/DoubleDeckerBus/src/main/resources/com/example/doubledeckerbus/images/LeftArrow.png b/DoubleDeckerBus/src/main/resources/com/example/doubledeckerbus/images/LeftArrow.png
new file mode 100644
index 0000000..51d95ac
Binary files /dev/null and b/DoubleDeckerBus/src/main/resources/com/example/doubledeckerbus/images/LeftArrow.png differ
diff --git a/DoubleDeckerBus/src/main/resources/com/example/doubledeckerbus/images/RightArrow.png b/DoubleDeckerBus/src/main/resources/com/example/doubledeckerbus/images/RightArrow.png
new file mode 100644
index 0000000..0ba3c35
Binary files /dev/null and b/DoubleDeckerBus/src/main/resources/com/example/doubledeckerbus/images/RightArrow.png differ
diff --git a/DoubleDeckerBus/src/main/resources/com/example/doubledeckerbus/images/UpArrow.png b/DoubleDeckerBus/src/main/resources/com/example/doubledeckerbus/images/UpArrow.png
new file mode 100644
index 0000000..d3c45c0
Binary files /dev/null and b/DoubleDeckerBus/src/main/resources/com/example/doubledeckerbus/images/UpArrow.png differ
diff --git a/README.md b/README.md
index 30221b2..ecb9f5c 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1,7 @@
# PIbd-21_Zaharchenko_M.I._DoubleDeckerBus._Hard
+## Требования:
+Проект работает на платформк javaFX. Нужно установить требуемые библиотеки.
+
+Также для удобства в IntelliJ стоит указать папку java как папку Sources root,
+а папку resources как папку Resources root
\ No newline at end of file