From a95007b753a5c34d9b8574b01b4349bd1dfd998f Mon Sep 17 00:00:00 2001 From: "ityurner02@mail.ru" Date: Sun, 4 Dec 2022 21:45:13 +0400 Subject: [PATCH] =?UTF-8?q?2=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...d-22_Turner_I.A._AntiAircraftGun._Hard.iml | 9 + AntiAircraftGun/.idea/uiDesigner.xml | 124 +++++++ .../example/antiaircraftgun/AbstractMap.java | 242 ++++++++++++++ .../antiaircraftgun/ControllerArmoredCar.java | 213 ++++++++++++ .../antiaircraftgun/ControllerMap.java | 182 +++++++++++ .../example/antiaircraftgun/DesertMap.java | 49 +++ .../example/antiaircraftgun/Direction.java | 3 + .../DrawingAntiAircraftGun.java | 60 ++++ .../antiaircraftgun/DrawingArmoredCar.java | 42 ++- .../DrawingObjectArmoredCar.java | 48 +++ .../DrawingOvalOrnamentRollers.java | 61 ++++ .../DrawingRectangleOrnamentRollers.java | 62 ++++ .../antiaircraftgun/DrawingRollers.java | 6 +- .../EntityAntiAircraftGun.java | 32 ++ .../antiaircraftgun/EntityArmoredCar.java | 8 +- .../antiaircraftgun/FormArmoredCar.java | 308 +++--------------- .../com/example/antiaircraftgun/FormMap.java | 75 +++++ .../IDrawingAdditionalElement.java | 8 + .../antiaircraftgun/IDrawingObject.java | 11 + .../example/antiaircraftgun/SimpleMap.java | 42 +++ .../antiaircraftgun/TrainingGroundMap.java | 42 +++ .../form-armored-vehicle-view.fxml | 96 ++++++ .../antiaircraftgun/form-map-view.fxml | 104 ++++++ .../example/antiaircraftgun/hello-view.fxml | 6 - 24 files changed, 1541 insertions(+), 292 deletions(-) create mode 100644 .idea/PIbd-22_Turner_I.A._AntiAircraftGun._Hard.iml create mode 100644 AntiAircraftGun/.idea/uiDesigner.xml create mode 100644 AntiAircraftGun/src/main/java/com/example/antiaircraftgun/AbstractMap.java create mode 100644 AntiAircraftGun/src/main/java/com/example/antiaircraftgun/ControllerArmoredCar.java create mode 100644 AntiAircraftGun/src/main/java/com/example/antiaircraftgun/ControllerMap.java create mode 100644 AntiAircraftGun/src/main/java/com/example/antiaircraftgun/DesertMap.java create mode 100644 AntiAircraftGun/src/main/java/com/example/antiaircraftgun/DrawingAntiAircraftGun.java create mode 100644 AntiAircraftGun/src/main/java/com/example/antiaircraftgun/DrawingObjectArmoredCar.java create mode 100644 AntiAircraftGun/src/main/java/com/example/antiaircraftgun/DrawingOvalOrnamentRollers.java create mode 100644 AntiAircraftGun/src/main/java/com/example/antiaircraftgun/DrawingRectangleOrnamentRollers.java create mode 100644 AntiAircraftGun/src/main/java/com/example/antiaircraftgun/EntityAntiAircraftGun.java create mode 100644 AntiAircraftGun/src/main/java/com/example/antiaircraftgun/FormMap.java create mode 100644 AntiAircraftGun/src/main/java/com/example/antiaircraftgun/IDrawingAdditionalElement.java create mode 100644 AntiAircraftGun/src/main/java/com/example/antiaircraftgun/IDrawingObject.java create mode 100644 AntiAircraftGun/src/main/java/com/example/antiaircraftgun/SimpleMap.java create mode 100644 AntiAircraftGun/src/main/java/com/example/antiaircraftgun/TrainingGroundMap.java create mode 100644 AntiAircraftGun/src/main/resources/com/example/antiaircraftgun/form-armored-vehicle-view.fxml create mode 100644 AntiAircraftGun/src/main/resources/com/example/antiaircraftgun/form-map-view.fxml delete mode 100644 AntiAircraftGun/src/main/resources/com/example/antiaircraftgun/hello-view.fxml diff --git a/.idea/PIbd-22_Turner_I.A._AntiAircraftGun._Hard.iml b/.idea/PIbd-22_Turner_I.A._AntiAircraftGun._Hard.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/.idea/PIbd-22_Turner_I.A._AntiAircraftGun._Hard.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/AntiAircraftGun/.idea/uiDesigner.xml b/AntiAircraftGun/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/AntiAircraftGun/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/AntiAircraftGun/src/main/java/com/example/antiaircraftgun/AbstractMap.java b/AntiAircraftGun/src/main/java/com/example/antiaircraftgun/AbstractMap.java new file mode 100644 index 0000000..c17cecb --- /dev/null +++ b/AntiAircraftGun/src/main/java/com/example/antiaircraftgun/AbstractMap.java @@ -0,0 +1,242 @@ +package com.example.antiaircraftgun; + +import javafx.scene.canvas.GraphicsContext; + +import java.util.Random; + +public abstract class AbstractMap { + private IDrawingObject _drawingObject = null; + private GraphicsContext _graphicsContext = null; + protected int[][] _map = null; + protected int _width; + protected int _height; + protected float _size_x; + protected float _size_y; + protected final Random _random = new Random(); + protected final int _freeRoad = 0; + protected final int _barrier = 1; + + public void CreateMap(int width, int height, IDrawingObject drawingObject, GraphicsContext gc) + { + _width = width; + _height = height; + _drawingObject = drawingObject; + _graphicsContext = gc; + GenerateMap(); + while (!SetObjectOnMap()) + { + GenerateMap(); + } + DrawMapWithObject(); + } + + public void MoveObject(Direction direction) + { + boolean roadIsClear = true; + + float[] position = _drawingObject.GetCurrentPosition(); + int xNumOfCells; + int yNumOfCells; + int xObjOffset; + int yObjOffset; + + switch (direction) + { + case Up: + xNumOfCells = (int)Math.ceil((position[2] - position[0]) / _size_x); + yNumOfCells = (int)Math.ceil(_drawingObject.GetStep() / _size_y); + xObjOffset = (int)(position[0] / _size_x); + yObjOffset = (int)Math.floor(position[1] / _size_y); + + for (int i = 0; i < yNumOfCells; i++) + { + if (!roadIsClear) + { + break; + } + for (int j = 0; j < xNumOfCells; j++) + { + if (yObjOffset - i < 0 || xObjOffset + j >= _map[0].length) + { + break; + } + if (_map[xObjOffset + j][yObjOffset - i] == _barrier) + { + roadIsClear = false; + break; + } + } + } + break; + + case Down: + xNumOfCells = (int)Math.ceil((position[2] - position[0]) / _size_x); + yNumOfCells = (int)Math.ceil(_drawingObject.GetStep() / _size_y); + xObjOffset = (int)(position[0] / _size_x); + yObjOffset = (int)Math.ceil(position[3]/ _size_y); + + for (int i = 0; i < yNumOfCells; i++) + { + if (!roadIsClear) + { + break; + } + for (int j = 0; j < xNumOfCells; j++) + { + if (yObjOffset + i >= _map.length || xObjOffset + j >= _map[0].length) + { + break; + } + if (_map[xObjOffset + j][yObjOffset + i] == _barrier) + { + roadIsClear = false; + break; + } + } + } + break; + + case Left: + xNumOfCells = (int)Math.ceil(_drawingObject.GetStep() / _size_x); + yNumOfCells = (int)Math.ceil((position[3] - position[1]) / _size_y); + xObjOffset = (int)Math.floor(position[0] / _size_x); + yObjOffset = (int)(position[1] / _size_y); + + for (int i = 0; i < yNumOfCells; i++) + { + if (!roadIsClear) + { + break; + } + for (int j = 0; j < xNumOfCells; j++) + { + if (yObjOffset + i >= _map.length || xObjOffset - j < 0) + { + break; + } + if (_map[xObjOffset - j][yObjOffset + i] == _barrier) + { + roadIsClear = false; + break; + } + } + } + break; + + case Right: + xNumOfCells = (int)Math.ceil(_drawingObject.GetStep() / _size_x); + yNumOfCells = (int)Math.ceil((position[3] - position[1]) / _size_y); + xObjOffset = (int)(position[2] / _size_x); + yObjOffset = (int)Math.ceil(position[1] / _size_y); + + for (int i = 0; i < yNumOfCells; i++) + { + if (!roadIsClear) + { + break; + } + for (int j = 0; j < xNumOfCells; j++) + { + if (yObjOffset + i >= _map.length || xObjOffset + j >= _map[0].length) + { + break; + } + if (_map[xObjOffset + j][yObjOffset + i] == _barrier) + { + roadIsClear = false; + break; + } + } + } + break; + } + if (roadIsClear) + { + _drawingObject.MoveObject(direction); + } + DrawMapWithObject(); + } + + private boolean SetObjectOnMap() + { + if (_drawingObject == null || _map == null) + { + return false; + } + int x = _random.nextInt(0, 10); + int y = _random.nextInt(0, 10); + + float[] position = _drawingObject.GetCurrentPosition(); + int xNumOfCells = (int)Math.ceil(position[2] / _size_x) - (int)Math.floor(position[0] / _size_x); + int yNumOfCells = (int)Math.ceil(position[3] / _size_y) - (int)Math.floor(position[1] / _size_y); + int xObjOffset = (int)(x / _size_x); + int yObjOffset = (int)(y / _size_y); + + while (y < _height - (position[3] - position[1])) + { + while (x < _width - (position[2] - position[0])) + { + if (AreaIsFree(xNumOfCells, yNumOfCells, xObjOffset, yObjOffset)) + { + _drawingObject.SetObject(x, y, _width, _height); + return true; + } + x += (int)_size_x; + xObjOffset = (int)(x / _size_x); + } + x = 0; + y += (int)_size_y; + yObjOffset = (int)(y / _size_y); + } + + return false; + } + + private boolean AreaIsFree(int xNumOfCells, int yNumOfCells, int xObjOffset, int yObjOffset) + { + for (int i = 0; i <= yNumOfCells; i++) + { + for (int j = 0; j <= xNumOfCells; j++) + { + if (yObjOffset + i >= _map.length || xObjOffset + j >= _map[0].length) + { + return false; + } + if (_map[xObjOffset + j][yObjOffset + i] == _barrier) + { + return false; + } + } + } + + return true; + } + + public void DrawMapWithObject() + { + if (_drawingObject == null || _map == null) + { + return; + } + + for (int i = 0; i < _map.length; ++i) + { + for (int j = 0; j < _map[0].length; ++j) + { + if (_map[i][j] == _freeRoad) + { + DrawRoadPart(_graphicsContext, i, j); + } + else if (_map[i][j] == _barrier) + { + DrawBarrierPart(_graphicsContext, i, j); + } + } + } + _drawingObject.DrawingObject(_graphicsContext); + } + + protected abstract void GenerateMap(); + protected abstract void DrawRoadPart(GraphicsContext gc, int i, int j); + protected abstract void DrawBarrierPart(GraphicsContext gc, int i, int j); +} diff --git a/AntiAircraftGun/src/main/java/com/example/antiaircraftgun/ControllerArmoredCar.java b/AntiAircraftGun/src/main/java/com/example/antiaircraftgun/ControllerArmoredCar.java new file mode 100644 index 0000000..34e514d --- /dev/null +++ b/AntiAircraftGun/src/main/java/com/example/antiaircraftgun/ControllerArmoredCar.java @@ -0,0 +1,213 @@ +package com.example.antiaircraftgun; + +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.ComboBox; +import javafx.scene.control.Label; +import javafx.scene.layout.FlowPane; +import javafx.scene.layout.Pane; +import javafx.scene.paint.Color; + +import java.util.Random; + +public class ControllerArmoredCar { + @FXML + private Pane root; + @FXML + private Canvas canvas; + @FXML + private FlowPane flowPane; + @FXML + private Label labelSpeedValue; + @FXML + private Label labelWeightValue; + @FXML + private Label labelBodyColorValue; + @FXML + private ComboBox comboBoxNumOfRollers; + @FXML + private ComboBox comboBoxOrnamentType; + @FXML + private Button buttonCreate; + @FXML + private Button buttonCreateModif; + @FXML + private Button buttonLeft; + @FXML + private Button buttonRight; + @FXML + private Button buttonUp; + @FXML + private Button buttonDown; + private final double rootPadding = 10.0; + private DrawingArmoredCar _armoredCar; + + @FXML + public void initialize() + { + buttonCreate.setTranslateX(rootPadding); + + root.widthProperty().addListener((obs, oldVal, newVal) -> + { + UpdateGUI(); + if (_armoredCar != null) + { + _armoredCar.ChangeBorders((int) canvas.getWidth(), (int) canvas.getHeight()); + } + Draw(); + }); + root.heightProperty().addListener((obs, oldVal, newVal) -> + { + UpdateGUI(); + if (_armoredCar != null) + { + _armoredCar.ChangeBorders((int) canvas.getWidth(), (int) canvas.getHeight()); + } + Draw(); + }); + } + + @FXML + void ButtonCreate_Click() + { + Random rnd = new Random(); + _armoredCar = new DrawingArmoredCar(rnd.nextInt(200) + 100, rnd.nextInt(1000) + 1000, + Color.rgb(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256))); + SetData(); + Draw(); + } + + @FXML + void ButtonCreateModif_Click() + { + Random rnd = new Random(); + _armoredCar = new DrawingAntiAircraftGun(rnd.nextInt(200) + 100, rnd.nextInt(1000) + 1000, + Color.rgb(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)), + Color.rgb(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)), + (rnd.nextInt(2) != 0), (rnd.nextInt(2) != 0)); + SetData(); + Draw(); + } + + @FXML + void ButtonMove_Click(ActionEvent event) + { + if (_armoredCar == null) + { + return; + } + String buttonName = ((Button) event.getSource()).getId(); + switch (buttonName) + { + case "buttonUp" -> _armoredCar.MoveTransport(Direction.Up); + case "buttonDown" -> _armoredCar.MoveTransport(Direction.Down); + case "buttonLeft" -> _armoredCar.MoveTransport(Direction.Left); + case "buttonRight" -> _armoredCar.MoveTransport(Direction.Right); + } + Draw(); + } + + @FXML + private void ComboBoxOrnamentType_Changed() + { + if (_armoredCar != null) + { + ChangeDrawingRollers(); + Draw(); + } + } + + @FXML + private void ComboBoxNumOfRollers_Changed() + { + if (_armoredCar != null) + { + _armoredCar.GetDrawingRollers().SetNumberRollers(Integer.parseInt(comboBoxNumOfRollers.getValue())); + Draw(); + } + } + + private void ChangeDrawingRollers() + { + if (_armoredCar != null) + { + IDrawingAdditionalElement newDrawingRollers = switch (comboBoxOrnamentType.getValue()) + { + case "None" -> new DrawingRollers(_armoredCar.GetArmoredCar().GetBodyColor()); + case "Rectangle" -> new DrawingRectangleOrnamentRollers(_armoredCar.GetArmoredCar().GetBodyColor()); + case "Oval" -> + new DrawingOvalOrnamentRollers(_armoredCar.GetArmoredCar().GetBodyColor()); + default -> null; + }; + if (newDrawingRollers != null) + { + _armoredCar.SetDrawingRollers(newDrawingRollers); + _armoredCar.GetDrawingRollers().SetNumberRollers(Integer.parseInt(comboBoxNumOfRollers.getValue())); + } + } + } + + private void UpdateGUI() + { + double rootWidth = root.getWidth(); + double rootHeight = root.getHeight(); + + double flowPaneHeight = flowPane.getHeight(); + double buttonCreateHeight = buttonCreate.getHeight(); + + canvas.setWidth(rootWidth); + flowPane.setPrefWidth(rootWidth); + canvas.setHeight(rootHeight - flowPaneHeight); + flowPane.setTranslateY(rootHeight - flowPaneHeight); + + buttonCreate.setTranslateY(rootHeight - flowPaneHeight - buttonCreateHeight - rootPadding); + buttonCreateModif.setTranslateY(rootHeight - flowPaneHeight - buttonCreateHeight - rootPadding); + + int buttonMoveSize = 30; + int distanceBetweenButtons = 5; + buttonUp.setTranslateY(rootHeight - flowPaneHeight - buttonMoveSize * 2.0 - rootPadding - + distanceBetweenButtons); + buttonUp.setTranslateX(rootWidth - rootPadding - buttonMoveSize * 2.0 - distanceBetweenButtons); + + buttonDown.setTranslateY(rootHeight - flowPaneHeight - buttonMoveSize - rootPadding); + buttonDown.setTranslateX(rootWidth- rootPadding - buttonMoveSize * 2.0 - distanceBetweenButtons); + + buttonLeft.setTranslateY(rootHeight - flowPaneHeight - buttonMoveSize - rootPadding); + buttonLeft.setTranslateX(rootWidth - rootPadding - buttonMoveSize * 3.0 - + distanceBetweenButtons * 2.0); + + buttonRight.setTranslateY(rootHeight - flowPaneHeight - buttonMoveSize - rootPadding); + buttonRight.setTranslateX(rootWidth - rootPadding - buttonMoveSize); + } + + private void Draw() + { + GraphicsContext gc = canvas.getGraphicsContext2D(); + + gc.clearRect(0.0, 0.0, canvas.getWidth(), canvas.getHeight()); + gc.setFill(Color.WHITE); + gc.fillRect(0.0, 0.0, canvas.getWidth(), canvas.getHeight()); + + gc.setStroke(Color.BLACK); + gc.setLineWidth(4); + gc.strokeRect(0.0, 0.0, canvas.getWidth(), canvas.getHeight()); + + if (_armoredCar != null) + { + _armoredCar.DrawTransport(gc); + } + } + + private void SetData() + { + ChangeDrawingRollers(); + Random rnd = new Random(); + _armoredCar.SetPosition(rnd.nextInt(90) + 10, rnd.nextInt(90) + 5, (int) canvas.getWidth(), (int) canvas.getHeight()); + labelSpeedValue.setText(Integer.toString(_armoredCar.GetArmoredCar().GetSpeed())); + labelWeightValue.setText(Double.toString(_armoredCar.GetArmoredCar().GetWeight())); + labelBodyColorValue.setText(_armoredCar.GetArmoredCar().GetBodyColor().toString()); + } +} diff --git a/AntiAircraftGun/src/main/java/com/example/antiaircraftgun/ControllerMap.java b/AntiAircraftGun/src/main/java/com/example/antiaircraftgun/ControllerMap.java new file mode 100644 index 0000000..a1dee09 --- /dev/null +++ b/AntiAircraftGun/src/main/java/com/example/antiaircraftgun/ControllerMap.java @@ -0,0 +1,182 @@ +package com.example.antiaircraftgun; + +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.ComboBox; +import javafx.scene.control.Label; +import javafx.scene.layout.FlowPane; +import javafx.scene.layout.Pane; +import javafx.scene.paint.Color; + +import java.util.Random; + +public class ControllerMap { + @FXML + private Pane root; + @FXML + private Canvas canvas; + @FXML + private FlowPane flowPane; + @FXML + private Label labelSpeedValue; + @FXML + private Label labelWeightValue; + @FXML + private Label labelBodyColorValue; + @FXML + private ComboBox comboBoxNumOfRollers; + @FXML + private ComboBox comboBoxOrnamentType; + @FXML + private ComboBox comboBoxSelectorMap; + @FXML + private Button buttonCreate; + @FXML + private Button buttonCreateModif; + @FXML + private Button buttonLeft; + @FXML + private Button buttonRight; + @FXML + private Button buttonUp; + @FXML + private Button buttonDown; + private final double buttonMargin = 10.0; + private AbstractMap _abstractMap; + + @FXML + public void initialize() + { + buttonCreate.setTranslateX(buttonMargin); + + root.widthProperty().addListener((obs, oldVal, newVal) -> + { + UpdateGUI(); + if (_abstractMap != null) + { + _abstractMap.DrawMapWithObject(); + } + }); + root.heightProperty().addListener((obs, oldVal, newVal) -> + { + UpdateGUI(); + if (_abstractMap != null) + { + _abstractMap.DrawMapWithObject(); + } + }); + } + + @FXML + void ButtonCreate_Click() + { + Random rnd = new Random(); + DrawingArmoredCar armoredCar = new DrawingArmoredCar(rnd.nextInt(200) + 100, rnd.nextInt(1000) + 1000, + Color.rgb(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256))); + SetData(armoredCar); + } + + @FXML + void ButtonCreateModif_Click() + { + Random rnd = new Random(); + DrawingAntiAircraftGun armoredCar = new DrawingAntiAircraftGun(rnd.nextInt(200) + 100, rnd.nextInt(1000) + 1000, + Color.rgb(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)), + Color.rgb(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)), + (rnd.nextInt(2) != 0), (rnd.nextInt(2) != 0)); + SetData(armoredCar); + } + + @FXML + void ButtonMove_Click(ActionEvent event) + { + if (_abstractMap == null) + { + return; + } + String buttonName = ((Button) event.getSource()).getId(); + switch (buttonName) + { + case "buttonUp" -> _abstractMap.MoveObject(Direction.Up); + case "buttonDown" -> _abstractMap.MoveObject(Direction.Down); + case "buttonLeft" -> _abstractMap.MoveObject(Direction.Left); + case "buttonRight" -> _abstractMap.MoveObject(Direction.Right); + } + } + + @FXML + private void ComboBoxSelectorMap_Changed() + { + switch (comboBoxSelectorMap.getValue()) + { + case "Simple map" -> _abstractMap = new SimpleMap(); + case "Training ground map" -> _abstractMap = new TrainingGroundMap(); + case "Desert map" -> _abstractMap = new DesertMap(); + } + } + + private void ChangeDrawningTrackRollers(DrawingArmoredCar armoredCar) + { + IDrawingAdditionalElement newDrawningTrackRollers = switch (comboBoxOrnamentType.getValue()) + { + case "None" -> new DrawingRollers(armoredCar.GetArmoredCar().GetBodyColor()); + case "Rectangle" -> new DrawingRectangleOrnamentRollers(armoredCar.GetArmoredCar().GetBodyColor()); + case "Oval" -> + new DrawingOvalOrnamentRollers(armoredCar.GetArmoredCar().GetBodyColor()); + default -> null; + }; + if (newDrawningTrackRollers != null) + { + armoredCar.SetDrawingRollers(newDrawningTrackRollers); + armoredCar.GetDrawingRollers().SetNumberRollers(Integer.parseInt(comboBoxNumOfRollers.getValue())); + } + } + + private void UpdateGUI() + { + double sceneWidth = root.getWidth(); + double sceneHeight = root.getHeight(); + + double flowPaneHeight = flowPane.getHeight(); + double buttonCreateHeight = buttonCreate.getHeight(); + + canvas.setWidth(sceneWidth); + flowPane.setPrefWidth(sceneWidth); + canvas.setHeight(sceneHeight - flowPaneHeight); + flowPane.setTranslateY(sceneHeight - flowPaneHeight); + + buttonCreate.setTranslateY(sceneHeight - flowPaneHeight - buttonCreateHeight - buttonMargin); + buttonCreateModif.setTranslateY(sceneHeight - flowPaneHeight - buttonCreateHeight - buttonMargin); + + int buttonMoveHeight = 30; + int distanceBetweenMoveButtons = 5; + buttonUp.setTranslateY(sceneHeight - flowPaneHeight - buttonMoveHeight * 2.0 - buttonMargin - + distanceBetweenMoveButtons); + int buttonMoveWidth = 30; + buttonUp.setTranslateX(sceneWidth - buttonMargin - buttonMoveWidth * 2.0 - distanceBetweenMoveButtons); + + buttonDown.setTranslateY(sceneHeight - flowPaneHeight - buttonMoveHeight - buttonMargin); + buttonDown.setTranslateX(sceneWidth- buttonMargin - buttonMoveWidth * 2.0 - distanceBetweenMoveButtons); + + buttonLeft.setTranslateY(sceneHeight - flowPaneHeight - buttonMoveHeight - buttonMargin); + buttonLeft.setTranslateX(sceneWidth - buttonMargin - buttonMoveWidth * 3.0 - + distanceBetweenMoveButtons * 2.0); + + buttonRight.setTranslateY(sceneHeight - flowPaneHeight - buttonMoveHeight - buttonMargin); + buttonRight.setTranslateX(sceneWidth - buttonMargin - buttonMoveWidth); + } + + private void SetData(DrawingArmoredCar armoredCar) + { + ChangeDrawningTrackRollers(armoredCar); + labelSpeedValue.setText(Integer.toString(armoredCar.GetArmoredCar().GetSpeed())); + labelWeightValue.setText(Double.toString(armoredCar.GetArmoredCar().GetWeight())); + labelBodyColorValue.setText(armoredCar.GetArmoredCar().GetBodyColor().toString()); + GraphicsContext gc = canvas.getGraphicsContext2D(); + gc.clearRect(0.0, 0.0, canvas.getWidth(), canvas.getHeight()); + _abstractMap.CreateMap((int)canvas.getWidth(), (int)canvas.getHeight(), new DrawingObjectArmoredCar(armoredCar), gc); + } +} diff --git a/AntiAircraftGun/src/main/java/com/example/antiaircraftgun/DesertMap.java b/AntiAircraftGun/src/main/java/com/example/antiaircraftgun/DesertMap.java new file mode 100644 index 0000000..6067478 --- /dev/null +++ b/AntiAircraftGun/src/main/java/com/example/antiaircraftgun/DesertMap.java @@ -0,0 +1,49 @@ +package com.example.antiaircraftgun; + +import javafx.scene.canvas.GraphicsContext; +import javafx.scene.paint.Color; + +public class DesertMap extends AbstractMap{ + protected void DrawBarrierPart(GraphicsContext gc, int i, int j) + { + gc.setFill(Color.BLACK); + gc.fillRect(i * _size_x, j * _size_y, _size_x + 0.5, _size_y + 0.5); + } + protected void DrawRoadPart(GraphicsContext gc, int i, int j) + { + gc.setFill(Color.YELLOW); + gc.fillRect(i * _size_x, j * _size_y, _size_x + 0.5, _size_y + 0.5); + } + + protected void GenerateMap() + { + _map = new int[100][100]; + _size_x = (float)_width / _map.length; + _size_y = (float)_height / _map[0].length; + int counter = 0; + for (int i = 0; i < _map.length; ++i) + { + for (int j = 0; j < _map[0].length; ++j) + { + _map[i][j] = _freeRoad; + } + } + while (counter < 10) + { + int x = _random.nextInt(0, 90); + int y = _random.nextInt(0, 90); + int length = _random.nextInt(5, 10); + if(counter < 5){ + for (int i = 0; i < length; i++) { + _map[x][y + i] = _barrier; + } + } + else{ + for (int i = 0; i < length; i++) { + _map[x + i][y] = _barrier; + } + } + counter++; + } + } +} diff --git a/AntiAircraftGun/src/main/java/com/example/antiaircraftgun/Direction.java b/AntiAircraftGun/src/main/java/com/example/antiaircraftgun/Direction.java index a1a4f28..e8a3d27 100644 --- a/AntiAircraftGun/src/main/java/com/example/antiaircraftgun/Direction.java +++ b/AntiAircraftGun/src/main/java/com/example/antiaircraftgun/Direction.java @@ -1,6 +1,7 @@ package com.example.antiaircraftgun; public enum Direction { + None, Up, Down, Left, @@ -10,6 +11,8 @@ public enum Direction { { switch(intValue) { + case 0: + return None; case 1: return Up; case 2: diff --git a/AntiAircraftGun/src/main/java/com/example/antiaircraftgun/DrawingAntiAircraftGun.java b/AntiAircraftGun/src/main/java/com/example/antiaircraftgun/DrawingAntiAircraftGun.java new file mode 100644 index 0000000..1cb87ea --- /dev/null +++ b/AntiAircraftGun/src/main/java/com/example/antiaircraftgun/DrawingAntiAircraftGun.java @@ -0,0 +1,60 @@ +package com.example.antiaircraftgun; + +import javafx.scene.canvas.GraphicsContext; +import javafx.scene.paint.Color; + +public class DrawingAntiAircraftGun extends DrawingArmoredCar{ + public DrawingAntiAircraftGun(int speed, float weight, Color bodyColor, Color dopColor, boolean gun, boolean radar) + { + super(speed, weight, bodyColor, 110, 75); + SetArmoredVehicle(new EntityAntiAircraftGun(speed, weight, bodyColor, dopColor, gun, radar)); + } + + @Override + public void DrawTransport(GraphicsContext gc) + { + if (!(GetArmoredCar() instanceof EntityAntiAircraftGun antiAircraftGun)) + { + return; + } + + _startPosY += 35; + super.DrawTransport(gc); + _startPosY -= 35; + + gc.setStroke(Color.BLACK); + + if (antiAircraftGun.GetGun()) + { + gc.setFill(antiAircraftGun.GetDopColor()); + gc.fillRect(_startPosX + 35, _startPosY + 20, 25, 15); + gc.fillRect(_startPosX + 60, _startPosY + 25, 50, 5); + gc.fillRect(_startPosX + 60, _startPosY + 30, 20, 5); + } + + if (antiAircraftGun.GetRadar()) + { + double[] radarX = + { + _startPosX + 32, + _startPosX + 32, + _startPosX + 22, + _startPosX + 10, + }; + + double[] radarY = + { + _startPosY + 3, + _startPosY + 15, + _startPosY + 25, + _startPosY + 25, + }; + gc.setStroke(antiAircraftGun.GetDopColor()); + gc.setFill(antiAircraftGun.GetDopColor()); + gc.strokeLine(_startPosX + 27, _startPosY + 35, _startPosX + 27, _startPosY + 20); + gc.fillPolygon(radarX, radarY, 4); + gc.strokeLine(_startPosX + 20, _startPosY + 15, _startPosX + 15, _startPosY + 10); + gc.fillOval(_startPosX + 10, _startPosY + 5, 10, 10); + } + } +} diff --git a/AntiAircraftGun/src/main/java/com/example/antiaircraftgun/DrawingArmoredCar.java b/AntiAircraftGun/src/main/java/com/example/antiaircraftgun/DrawingArmoredCar.java index 8a9ef14..c4340b2 100644 --- a/AntiAircraftGun/src/main/java/com/example/antiaircraftgun/DrawingArmoredCar.java +++ b/AntiAircraftGun/src/main/java/com/example/antiaircraftgun/DrawingArmoredCar.java @@ -6,9 +6,9 @@ import javafx.scene.paint.Color; public class DrawingArmoredCar { private EntityArmoredCar _armoredCar; - private DrawingRollers _drawingRollers; - private float _startPosX; - private float _startPosY; + private IDrawingAdditionalElement _drawingRollers; + protected float _startPosX; + protected float _startPosY; private Integer _pictureWidth; private Integer _pictureHeight; private int _armoredCarWidth = 90; @@ -18,20 +18,29 @@ public class DrawingArmoredCar { return _armoredCar; } - public DrawingRollers GetDrawningRollers() + protected void SetArmoredVehicle(EntityArmoredCar armoredCar) + { + _armoredCar = armoredCar; + } + public IDrawingAdditionalElement GetDrawingRollers() { return _drawingRollers; } - - public void Init(int speed, float weight, Color bodyColor) + public void SetDrawingRollers(IDrawingAdditionalElement drawingRollers) { - _armoredCar = new EntityArmoredCar(); - _armoredCar.Init(speed, weight, bodyColor); - - _drawingRollers = new DrawingRollers(); - _drawingRollers.Init(bodyColor); + _drawingRollers = drawingRollers; + } + public DrawingArmoredCar(int speed, float weight, Color bodyColor) + { + _armoredCar = new EntityArmoredCar(speed, weight, bodyColor); + _drawingRollers = new DrawingRollers(bodyColor); + } + protected DrawingArmoredCar(int speed, float weight, Color bodyColor, int armoredCarWidth, int armoredCarHeight) + { + this(speed, weight, bodyColor); + _armoredCarHeight = armoredCarHeight; + _armoredCarWidth = armoredCarWidth; } - public void SetPosition(int x, int y, int width, int height) { if (x < 0 || y < 0) { @@ -130,4 +139,13 @@ public class DrawingArmoredCar _startPosY = _pictureHeight - _armoredCarHeight; } } + public float[] GetCurrentPosition() + { + float[] position = new float[4]; + position[0] = _startPosX; + position[1] = _startPosY; + position[2] = _startPosX + _armoredCarWidth; + position[3] = _startPosY + _armoredCarHeight; + return position; + } } diff --git a/AntiAircraftGun/src/main/java/com/example/antiaircraftgun/DrawingObjectArmoredCar.java b/AntiAircraftGun/src/main/java/com/example/antiaircraftgun/DrawingObjectArmoredCar.java new file mode 100644 index 0000000..89b1e6b --- /dev/null +++ b/AntiAircraftGun/src/main/java/com/example/antiaircraftgun/DrawingObjectArmoredCar.java @@ -0,0 +1,48 @@ +package com.example.antiaircraftgun; + +import javafx.scene.canvas.GraphicsContext; + +public class DrawingObjectArmoredCar implements IDrawingObject{ + private DrawingArmoredCar _armoredCar = null; + + public DrawingObjectArmoredCar(DrawingArmoredCar armoredCar) + { + _armoredCar = armoredCar; + } + + public float GetStep() + { + if (_armoredCar != null && _armoredCar.GetArmoredCar() != null) + { + return _armoredCar.GetArmoredCar().GetStep(); + } + return 0F; + } + + public float[] GetCurrentPosition() + { + if (_armoredCar != null) + { + return _armoredCar.GetCurrentPosition(); + } + return new float[4]; + } + + public void MoveObject(Direction direction) + { + _armoredCar.MoveTransport(direction); + } + + public void SetObject(int x, int y, int width, int height) + { + _armoredCar.SetPosition(x, y, width, height); + } + + public void DrawingObject(GraphicsContext gc) + { + if (_armoredCar != null) + { + _armoredCar.DrawTransport(gc); + } + } +} diff --git a/AntiAircraftGun/src/main/java/com/example/antiaircraftgun/DrawingOvalOrnamentRollers.java b/AntiAircraftGun/src/main/java/com/example/antiaircraftgun/DrawingOvalOrnamentRollers.java new file mode 100644 index 0000000..ef24d5d --- /dev/null +++ b/AntiAircraftGun/src/main/java/com/example/antiaircraftgun/DrawingOvalOrnamentRollers.java @@ -0,0 +1,61 @@ +package com.example.antiaircraftgun; + +import javafx.scene.canvas.GraphicsContext; +import javafx.scene.paint.Color; + +public class DrawingOvalOrnamentRollers implements IDrawingAdditionalElement{ + private Color _rollersColor; + private NumberRollers _numOfRollers; + + public void SetNumberRollers(int numberOfRollers) + { + _numOfRollers = NumberRollers.FromInteger(numberOfRollers); + } + + public DrawingOvalOrnamentRollers(Color trackRollersColor) + { + _rollersColor = trackRollersColor; + } + + public void DrawRollers(GraphicsContext gc, float startPosX, float startPosY) + { + if (_rollersColor == null) + { + return; + } + + gc.setFill(_rollersColor); + gc.fillOval(startPosX +1, startPosY + 21, 18, 18); + gc.fillOval(startPosX + 69, startPosY + 21, 18, 18); + gc.fillOval(startPosX + 19, startPosY + 30, 11, 11); + gc.fillOval(startPosX + 58, startPosY + 30, 11, 11); + + // Орнамент + gc.strokeOval(startPosX + 5, startPosY + 25, 10, 10); + gc.strokeOval(startPosX + 73, startPosY + 25, 10, 10); + gc.strokeOval(startPosX + 22, startPosY + 33, 5, 5); + gc.strokeOval(startPosX + 61, startPosY + 33, 5, 5); + + switch (_numOfRollers) + { + case Four: + break; + + case Five: + gc.setFill(_rollersColor); + gc.fillOval(startPosX + 45, startPosY + 30, 11, 11); + // Орнамент + gc.strokeOval(startPosX + 48, startPosY + 33, 5, 5); + break; + + case Six: + gc.setFill(_rollersColor); + gc.fillOval(startPosX + 45, startPosY + 30, 11, 11); + gc.fillOval(startPosX + 32, startPosY + 30, 11, 11); + // Орнамент + gc.strokeOval(startPosX + 48, startPosY + 33, 5, 5); + gc.strokeOval(startPosX + 35, startPosY + 33, 5, 5); + break; + } + } +} diff --git a/AntiAircraftGun/src/main/java/com/example/antiaircraftgun/DrawingRectangleOrnamentRollers.java b/AntiAircraftGun/src/main/java/com/example/antiaircraftgun/DrawingRectangleOrnamentRollers.java new file mode 100644 index 0000000..df8bd9d --- /dev/null +++ b/AntiAircraftGun/src/main/java/com/example/antiaircraftgun/DrawingRectangleOrnamentRollers.java @@ -0,0 +1,62 @@ +package com.example.antiaircraftgun; + +import javafx.scene.canvas.GraphicsContext; +import javafx.scene.paint.Color; + +public class DrawingRectangleOrnamentRollers implements IDrawingAdditionalElement{ + private Color _rollersColor; + private NumberRollers _numOfRollers; + + public void SetNumberRollers(int numberOfRollers) + { + _numOfRollers = NumberRollers.FromInteger(numberOfRollers); + } + + public DrawingRectangleOrnamentRollers(Color trackRollersColor) + { + _rollersColor = trackRollersColor; + } + + public void DrawRollers(GraphicsContext gc, float startPosX, float startPosY) + { + if (_rollersColor == null) + { + return; + } + gc.setFill(_rollersColor); + gc.fillOval(startPosX +1, startPosY + 21, 18, 18); + gc.fillOval(startPosX + 69, startPosY + 21, 18, 18); + gc.fillOval(startPosX + 19, startPosY + 30, 11, 11); + gc.fillOval(startPosX + 58, startPosY + 30, 11, 11); + + // Орнамент + gc.strokeRect(startPosX + 5, startPosY + 25, 10, 10); + gc.strokeRect(startPosX + 73, startPosY + 25, 10, 10); + gc.strokeRect(startPosX + 22, startPosY + 33, 5, 5); + gc.strokeRect(startPosX + 61, startPosY + 33, 5, 5); + gc.strokeRect(startPosX + 9, startPosY + 28, 3, 3); + gc.strokeRect(startPosX + 77, startPosY + 28, 3, 3); + + switch (_numOfRollers) + { + case Four: + break; + + case Five: + gc.setFill(_rollersColor); + gc.fillOval(startPosX + 45, startPosY + 30, 11, 11); + // Орнамент + gc.strokeRect(startPosX + 48, startPosY + 33, 5, 5); + break; + + case Six: + gc.setFill(_rollersColor); + gc.fillOval(startPosX + 45, startPosY + 30, 11, 11); + gc.fillOval(startPosX + 32, startPosY + 30, 11, 11); + // Орнамент + gc.strokeRect(startPosX + 48, startPosY + 33, 5, 5); + gc.strokeRect(startPosX + 35, startPosY + 33, 5, 5); + break; + } + } +} diff --git a/AntiAircraftGun/src/main/java/com/example/antiaircraftgun/DrawingRollers.java b/AntiAircraftGun/src/main/java/com/example/antiaircraftgun/DrawingRollers.java index 935a54b..cd2cc63 100644 --- a/AntiAircraftGun/src/main/java/com/example/antiaircraftgun/DrawingRollers.java +++ b/AntiAircraftGun/src/main/java/com/example/antiaircraftgun/DrawingRollers.java @@ -3,16 +3,16 @@ package com.example.antiaircraftgun; import javafx.scene.canvas.GraphicsContext; import javafx.scene.paint.Color; -public class DrawingRollers { +public class DrawingRollers implements IDrawingAdditionalElement{ private Color _RollersColor; private NumberRollers _numRollers; public void SetNumberRollers(int numberRollers) { _numRollers = NumberRollers.FromInteger(numberRollers); } - public void Init(Color trackRollersColor) + public DrawingRollers(Color rollersColor) { - _RollersColor = trackRollersColor; + _RollersColor = rollersColor; } public void DrawRollers(GraphicsContext gc, float startPosX, float startPosY) { diff --git a/AntiAircraftGun/src/main/java/com/example/antiaircraftgun/EntityAntiAircraftGun.java b/AntiAircraftGun/src/main/java/com/example/antiaircraftgun/EntityAntiAircraftGun.java new file mode 100644 index 0000000..5b0efd2 --- /dev/null +++ b/AntiAircraftGun/src/main/java/com/example/antiaircraftgun/EntityAntiAircraftGun.java @@ -0,0 +1,32 @@ +package com.example.antiaircraftgun; + +import javafx.scene.paint.Color; + +public class EntityAntiAircraftGun extends EntityArmoredCar{ + private final Color _dopColor; + private final boolean _gun; + private final boolean _radar; + + public Color GetDopColor() + { + return _dopColor; + } + + public boolean GetGun() + { + return _gun; + } + + public boolean GetRadar() + { + return _radar; + } + + public EntityAntiAircraftGun(int speed, float weight, Color bodyColor, Color dopColor, boolean gun, boolean radar) + { + super(speed, weight, bodyColor); + _dopColor = dopColor; + _gun = gun; + _radar = radar; + } +} diff --git a/AntiAircraftGun/src/main/java/com/example/antiaircraftgun/EntityArmoredCar.java b/AntiAircraftGun/src/main/java/com/example/antiaircraftgun/EntityArmoredCar.java index ecbd464..bbaa48e 100644 --- a/AntiAircraftGun/src/main/java/com/example/antiaircraftgun/EntityArmoredCar.java +++ b/AntiAircraftGun/src/main/java/com/example/antiaircraftgun/EntityArmoredCar.java @@ -5,9 +5,9 @@ import java.util.Random; public class EntityArmoredCar { - private int _speed; - private float _weight; - private Color _bodyColor; + private final int _speed; + private final float _weight; + private final Color _bodyColor; public int GetSpeed() { return _speed; @@ -28,7 +28,7 @@ public class EntityArmoredCar return _speed * 100 / _weight; } - public void Init(int speed, float weight, Color bodyColor) + public EntityArmoredCar(int speed, float weight, Color bodyColor) { Random random = new Random(); _speed = speed <= 0 ? random.nextInt(100) + 50 : speed; diff --git a/AntiAircraftGun/src/main/java/com/example/antiaircraftgun/FormArmoredCar.java b/AntiAircraftGun/src/main/java/com/example/antiaircraftgun/FormArmoredCar.java index 494c84f..6839aad 100644 --- a/AntiAircraftGun/src/main/java/com/example/antiaircraftgun/FormArmoredCar.java +++ b/AntiAircraftGun/src/main/java/com/example/antiaircraftgun/FormArmoredCar.java @@ -1,303 +1,77 @@ package com.example.antiaircraftgun; import javafx.application.Application; -import javafx.collections.FXCollections; -import javafx.collections.ObservableList; import javafx.fxml.FXMLLoader; import javafx.scene.Scene; import javafx.scene.canvas.Canvas; -import javafx.scene.canvas.GraphicsContext; import javafx.scene.control.Button; -import javafx.scene.control.ComboBox; -import javafx.scene.control.Label; -import javafx.scene.image.Image; -import javafx.scene.image.ImageView; -import javafx.scene.layout.HBox; +import javafx.scene.layout.FlowPane; import javafx.scene.layout.Pane; -import javafx.scene.paint.Color; import javafx.stage.Stage; import java.io.IOException; -import java.util.Random; public class FormArmoredCar extends Application { - private Pane _root; - private Scene _scene; - private Canvas _canvas; - private HBox _hBox; - private Button _buttonCreate; - private Button _buttonUp; - private Button _buttonDown; - private Button _buttonLeft; - private Button _buttonRight; - private Label _labelSpeedValue; - private Label _labelWeightValue; - private Label _labelBodyColorValue; - private ComboBox _comboBoxNumRollers; - private double _hBoxHeight; - private double _buttonCreateHeight; - private final int _buttonMoveWidth = 30; - private final int _buttonMoveHeight = 30; - private final int _distanceBetweenMoveButtons = 5; - private final double _buttonMargin = 10.0; - private DrawingArmoredCar _armoredCar; - @Override public void start(Stage stage) throws IOException { - FXMLLoader fxmlLoader = new FXMLLoader(FormArmoredCar.class.getResource("hello-view.fxml")); - _scene = new Scene(fxmlLoader.load(), 600, 400); - - _root = (Pane) _scene.lookup("#root"); - _root.setStyle("-fx-background-color: #31374c;"); - - _canvas = new Canvas(); - _root.getChildren().add(_canvas); - - InitHBox(); - InitButtonCreate(); - InitMoveButtons(); + FXMLLoader fxmlLoader = new FXMLLoader(FormArmoredCar.class.getResource("form-armored-vehicle-view.fxml")); + Scene scene = new Scene(fxmlLoader.load(), 600, 400); stage.setTitle("AntiAircraftGun"); - stage.setScene(_scene); - _scene.widthProperty().addListener((obs, oldVal, newVal) -> { - UpdateGUI(); - if (_armoredCar != null) - { - _armoredCar.ChangeBorders((int) _canvas.getWidth(), (int) _canvas.getHeight()); - } - Draw(); - }); - - _scene.heightProperty().addListener((obs, oldVal, newVal) -> { - UpdateGUI(); - if (_armoredCar != null) - { - _armoredCar.ChangeBorders((int) _canvas.getWidth(), (int) _canvas.getHeight()); - } - Draw(); - }); - - _root.applyCss(); - _root.layout(); - - stage.setOnShowing(event -> { - _hBoxHeight = _hBox.getHeight(); - _buttonCreateHeight = _buttonCreate.getHeight(); - UpdateGUI(); - Draw(); - }); + stage.setScene(scene); + FirstUpdateGUI(scene); stage.show(); } - private void InitHBox() + private void FirstUpdateGUI(Scene scene) { - _hBox = new HBox(); - _hBox.setStyle("-fx-background-color: #31374c;"); - _root.getChildren().add(_hBox); + Pane root = (Pane)scene.lookup("#root"); + Canvas canvas = (Canvas)scene.lookup("#canvas"); + Button buttonCreate = (Button)scene.lookup("#buttonCreate"); + Button buttonCreateModif = (Button)scene.lookup("#buttonCreateModif"); + Button buttonUp = (Button)scene.lookup("#buttonUp"); + Button buttonLeft = (Button)scene.lookup("#buttonLeft"); + Button buttonRight = (Button)scene.lookup("#buttonRight"); + Button buttonDown = (Button)scene.lookup("#buttonDown"); + FlowPane flowPane = (FlowPane)scene.lookup("#flowPane"); - Label labelSpeed = new Label("Speed:"); - labelSpeed.setStyle("-fx-text-fill: #b8becc; -fx-padding: 5 5 5 5;"); - _hBox.getChildren().add(labelSpeed); + root.applyCss(); + root.layout(); - _labelSpeedValue = new Label("-"); - _labelSpeedValue.setStyle("-fx-text-fill: #ffffff; -fx-padding: 5 5 5 0; -fx-font-weight: bold;"); - _hBox.getChildren().add(_labelSpeedValue); + double flowPaneHeight = flowPane.getHeight(); + double buttonCreateHeight = buttonCreate.getHeight(); + double buttonCreateWidth = buttonCreate.getWidth(); + double rootWidth = root.getWidth(); + double rootHeight = root.getHeight(); + double rootPadding = 10.0; + double distanceBetweenButtons = 5.0; + double buttonMoveSize = 30.0; - Label labelWeight = new Label("Weight:"); - labelWeight.setStyle("-fx-text-fill: #b8becc; -fx-padding: 5 5 5 5;"); - _hBox.getChildren().add(labelWeight); + canvas.setWidth(rootWidth); + flowPane.setPrefWidth(rootWidth); + canvas.setHeight(rootHeight - flowPaneHeight); + flowPane.setTranslateY(rootHeight - flowPaneHeight); + buttonCreateModif.setTranslateX(rootPadding + buttonCreateWidth + distanceBetweenButtons); + buttonCreate.setTranslateY(rootHeight - flowPaneHeight - buttonCreateHeight - rootPadding); + buttonCreateModif.setTranslateY(rootHeight - flowPaneHeight - buttonCreateHeight - rootPadding); - _labelWeightValue = new Label("-"); - _labelWeightValue.setStyle("-fx-text-fill: #ffffff; -fx-padding: 5 5 5 0; -fx-font-weight: bold;"); - _hBox.getChildren().add(_labelWeightValue); + buttonUp.setTranslateY(rootHeight - flowPaneHeight - buttonMoveSize * 2.0 - rootPadding - + distanceBetweenButtons); + buttonUp.setTranslateX(rootWidth - rootPadding - buttonMoveSize * 2.0 - distanceBetweenButtons); - Label labelHullColor = new Label("Color:"); - labelHullColor.setStyle("-fx-text-fill: #b8becc; -fx-padding: 5 5 5 5;"); - _hBox.getChildren().add(labelHullColor); + buttonDown.setTranslateY(rootHeight - flowPaneHeight - buttonMoveSize - rootPadding); + buttonDown.setTranslateX(rootWidth- rootPadding - buttonMoveSize * 2.0 - distanceBetweenButtons); - _labelBodyColorValue = new Label("-"); - _labelBodyColorValue.setStyle("-fx-text-fill: #ffffff; -fx-padding: 5 5 5 0; -fx-font-weight: bold;"); - _hBox.getChildren().add(_labelBodyColorValue); + buttonLeft.setTranslateY(rootHeight - flowPaneHeight - buttonMoveSize - rootPadding); + buttonLeft.setTranslateX(rootWidth - rootPadding - buttonMoveSize * 3.0 - distanceBetweenButtons * 2.0); - Label labelNumRollers = new Label("Rollers:"); - labelNumRollers.setStyle("-fx-text-fill: #b8becc; -fx-padding: 5 5 5 5;"); - _hBox.getChildren().add(labelNumRollers); - - ObservableList optionsForNumRollers = FXCollections.observableArrayList("4", "5", "6"); - _comboBoxNumRollers = new ComboBox<>(optionsForNumRollers); - _comboBoxNumRollers.setValue("4"); - - _comboBoxNumRollers.setOnAction(e -> { - if (_armoredCar != null) { - _armoredCar.GetDrawningRollers().SetNumberRollers(Integer.parseInt(_comboBoxNumRollers.getValue())); - Draw(); - } - }); - - _hBox.getChildren().add(_comboBoxNumRollers); + buttonRight.setTranslateY(rootHeight - flowPaneHeight - buttonMoveSize - rootPadding); + buttonRight.setTranslateX(rootWidth - rootPadding - buttonMoveSize); } - private void InitButtonCreate() - { - _buttonCreate = new Button("Create"); - _buttonCreate.setTranslateX(_buttonMargin); - _root.getChildren().add(_buttonCreate); - - _buttonCreate.setOnAction(e -> { - Random rnd = new Random(); - - _armoredCar = new DrawingArmoredCar(); - _armoredCar.Init(rnd.nextInt(200) + 100, rnd.nextInt(1000) + 1000, - Color.rgb(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256))); - _armoredCar.SetPosition(rnd.nextInt(90) + 10, rnd.nextInt(90)+10, - (int) _canvas.getWidth(), (int) _canvas.getHeight()); - - _armoredCar.GetDrawningRollers().SetNumberRollers(Integer.parseInt(_comboBoxNumRollers.getValue())); - - _labelSpeedValue.setText(Integer.toString(_armoredCar.GetArmoredCar().GetSpeed())); - _labelWeightValue.setText(Double.toString(_armoredCar.GetArmoredCar().GetWeight())); - _labelBodyColorValue.setText(_armoredCar.GetArmoredCar().GetBodyColor().toString()); - - Draw(); - }); - } - private void InitMoveButtons() - { - Image img; - ImageView view; - - // Button "Up" - _buttonUp = new Button(); - - img = new Image("arrowUp.png"); - view = new ImageView(img); - view.setFitHeight(14); - view.setFitWidth(14); - _buttonUp.setGraphic(view); - - _buttonUp.setPrefWidth(_buttonMoveWidth); - _buttonUp.setPrefHeight(_buttonMoveHeight); - - _buttonUp.setOnAction(e -> { - if (_armoredCar != null) { - _armoredCar.MoveTransport(Direction.Up); - Draw(); - } - }); - - _root.getChildren().add(_buttonUp); - - // Button "Down" - _buttonDown = new Button(); - - img = new Image("arrowDown.png"); - view = new ImageView(img); - view.setFitHeight(14); - view.setFitWidth(14); - _buttonDown.setGraphic(view); - - _buttonDown.setPrefWidth(_buttonMoveWidth); - _buttonDown.setPrefHeight(_buttonMoveHeight); - - _buttonDown.setOnAction(e -> { - if (_armoredCar != null) { - _armoredCar.MoveTransport(Direction.Down); - Draw(); - } - }); - - _root.getChildren().add(_buttonDown); - - // Button "Left" - _buttonLeft = new Button(); - - img = new Image("arrowLeft.png"); - view = new ImageView(img); - view.setFitHeight(14); - view.setFitWidth(14); - _buttonLeft.setGraphic(view); - - _buttonLeft.setPrefWidth(_buttonMoveWidth); - _buttonLeft.setPrefHeight(_buttonMoveHeight); - - _buttonLeft.setOnAction(e -> { - if (_armoredCar != null) { - _armoredCar.MoveTransport(Direction.Left); - Draw(); - } - }); - - _root.getChildren().add(_buttonLeft); - - // Button "Right" - _buttonRight = new Button(); - - img = new Image("arrowRight.png"); - view = new ImageView(img); - view.setFitHeight(14); - view.setFitWidth(14); - _buttonRight.setGraphic(view); - - _buttonRight.setPrefWidth(_buttonMoveWidth); - _buttonRight.setPrefHeight(_buttonMoveHeight); - - _buttonRight.setOnAction(e -> { - if (_armoredCar != null) { - _armoredCar.MoveTransport(Direction.Right); - Draw(); - } - }); - - _root.getChildren().add(_buttonRight); - } - private void UpdateGUI() - { - double sceneWidth = _scene.getWidth(); - double sceneHeight = _scene.getHeight(); - - _canvas.setWidth(sceneWidth); - _hBox.setPrefWidth(sceneWidth); - _canvas.setHeight(sceneHeight - _hBoxHeight); - _hBox.setTranslateY(sceneHeight - _hBoxHeight); - - _buttonCreate.setTranslateY(sceneHeight - _hBoxHeight - _buttonCreateHeight - _buttonMargin); - - _buttonUp.setTranslateY(sceneHeight - _hBoxHeight - _buttonMoveHeight * 2.0 - _buttonMargin - - _distanceBetweenMoveButtons); - _buttonUp.setTranslateX(sceneWidth - _buttonMargin - _buttonMoveWidth * 2.0 - _distanceBetweenMoveButtons); - - _buttonDown.setTranslateY(sceneHeight - _hBoxHeight - _buttonMoveHeight - _buttonMargin); - _buttonDown.setTranslateX(sceneWidth- _buttonMargin - _buttonMoveWidth * 2.0 - _distanceBetweenMoveButtons); - - _buttonLeft.setTranslateY(sceneHeight - _hBoxHeight - _buttonMoveHeight - _buttonMargin); - _buttonLeft.setTranslateX(sceneWidth - _buttonMargin - _buttonMoveWidth * 3.0 - - _distanceBetweenMoveButtons * 2.0); - - _buttonRight.setTranslateY(sceneHeight - _hBoxHeight - _buttonMoveHeight - _buttonMargin); - _buttonRight.setTranslateX(sceneWidth - _buttonMargin - _buttonMoveWidth); - } - - private void Draw() - { - GraphicsContext gc = _canvas.getGraphicsContext2D(); - - gc.clearRect(0.0, 0.0, _canvas.getWidth(), _canvas.getHeight()); - gc.setFill(Color.WHITE); - gc.fillRect(0.0, 0.0, _canvas.getWidth(), _canvas.getHeight()); - - gc.setStroke(Color.BLACK); - gc.setLineWidth(4); - gc.strokeRect(0.0, 0.0, _canvas.getWidth(), _canvas.getHeight()); - - if (_armoredCar != null) - { - _armoredCar.DrawTransport(gc); - } - } - public static void main(String[] args) { launch(); diff --git a/AntiAircraftGun/src/main/java/com/example/antiaircraftgun/FormMap.java b/AntiAircraftGun/src/main/java/com/example/antiaircraftgun/FormMap.java new file mode 100644 index 0000000..76e81a1 --- /dev/null +++ b/AntiAircraftGun/src/main/java/com/example/antiaircraftgun/FormMap.java @@ -0,0 +1,75 @@ +package com.example.antiaircraftgun; + +import javafx.application.Application; +import javafx.fxml.FXMLLoader; +import javafx.scene.Scene; +import javafx.scene.canvas.Canvas; +import javafx.scene.control.Button; +import javafx.scene.layout.FlowPane; +import javafx.scene.layout.Pane; +import javafx.stage.Stage; + +import java.io.IOException; + +public class FormMap extends Application{ + @Override + public void start(Stage stage) throws IOException + { + FXMLLoader fxmlLoader = new FXMLLoader(FormMap.class.getResource("form-map-view.fxml")); + Scene scene = new Scene(fxmlLoader.load(), 600, 400); + + stage.setTitle("Map"); + stage.setScene(scene); + + FirstUpdateGUI(scene); + stage.show(); + } + + private void FirstUpdateGUI(Scene scene) + { + Pane root = (Pane)scene.lookup("#root"); + Canvas canvas = (Canvas)scene.lookup("#canvas"); + Button buttonCreate = (Button)scene.lookup("#buttonCreate"); + Button buttonCreateModif = (Button)scene.lookup("#buttonCreateModif"); + Button buttonUp = (Button)scene.lookup("#buttonUp"); + Button buttonLeft = (Button)scene.lookup("#buttonLeft"); + Button buttonRight = (Button)scene.lookup("#buttonRight"); + Button buttonDown = (Button)scene.lookup("#buttonDown"); + FlowPane flowPane = (FlowPane)scene.lookup("#flowPane"); + + root.applyCss(); + root.layout(); + + double flowPaneHeight = flowPane.getHeight(); + double buttonCreateHeight = buttonCreate.getHeight(); + double buttonCreateWidth = buttonCreate.getWidth(); + double rootWidth = root.getWidth(); + double rootHeight = root.getHeight(); + double rootPadding = 10.0; + double distanceBetweenButtons = 5.0; + double buttonMoveSize = 30.0; + + canvas.setWidth(rootWidth); + flowPane.setPrefWidth(rootWidth); + canvas.setHeight(rootHeight - flowPaneHeight); + flowPane.setTranslateY(rootHeight - flowPaneHeight); + buttonCreateModif.setTranslateX(rootPadding + buttonCreateWidth + distanceBetweenButtons); + buttonCreate.setTranslateY(rootHeight - flowPaneHeight - buttonCreateHeight - rootPadding); + buttonCreateModif.setTranslateY(rootHeight - flowPaneHeight - buttonCreateHeight - rootPadding); + + buttonUp.setTranslateY(rootHeight - flowPaneHeight - buttonMoveSize * 2.0 - rootPadding - + distanceBetweenButtons); + buttonUp.setTranslateX(rootWidth - rootPadding - buttonMoveSize * 2.0 - distanceBetweenButtons); + + buttonDown.setTranslateY(rootHeight - flowPaneHeight - buttonMoveSize - rootPadding); + buttonDown.setTranslateX(rootWidth- rootPadding - buttonMoveSize * 2.0 - distanceBetweenButtons); + + buttonLeft.setTranslateY(rootHeight - flowPaneHeight - buttonMoveSize - rootPadding); + buttonLeft.setTranslateX(rootWidth - rootPadding - buttonMoveSize * 3.0 - distanceBetweenButtons * 2.0); + + buttonRight.setTranslateY(rootHeight - flowPaneHeight - buttonMoveSize - rootPadding); + buttonRight.setTranslateX(rootWidth - rootPadding - buttonMoveSize); + } + + public static void main(String[] args) { launch(); } +} diff --git a/AntiAircraftGun/src/main/java/com/example/antiaircraftgun/IDrawingAdditionalElement.java b/AntiAircraftGun/src/main/java/com/example/antiaircraftgun/IDrawingAdditionalElement.java new file mode 100644 index 0000000..4534ab8 --- /dev/null +++ b/AntiAircraftGun/src/main/java/com/example/antiaircraftgun/IDrawingAdditionalElement.java @@ -0,0 +1,8 @@ +package com.example.antiaircraftgun; + +import javafx.scene.canvas.GraphicsContext; + +public interface IDrawingAdditionalElement { + public void SetNumberRollers(int numberOfRollers); + public void DrawRollers(GraphicsContext gc, float startPosX, float startPosY); +} diff --git a/AntiAircraftGun/src/main/java/com/example/antiaircraftgun/IDrawingObject.java b/AntiAircraftGun/src/main/java/com/example/antiaircraftgun/IDrawingObject.java new file mode 100644 index 0000000..b7a798f --- /dev/null +++ b/AntiAircraftGun/src/main/java/com/example/antiaircraftgun/IDrawingObject.java @@ -0,0 +1,11 @@ +package com.example.antiaircraftgun; + +import javafx.scene.canvas.GraphicsContext; + +public interface IDrawingObject { + public float GetStep(); + public void SetObject(int x, int y, int width, int height); + public void MoveObject(Direction direction); + public void DrawingObject(GraphicsContext gc); + public float[] GetCurrentPosition(); +} \ No newline at end of file diff --git a/AntiAircraftGun/src/main/java/com/example/antiaircraftgun/SimpleMap.java b/AntiAircraftGun/src/main/java/com/example/antiaircraftgun/SimpleMap.java new file mode 100644 index 0000000..87e53dc --- /dev/null +++ b/AntiAircraftGun/src/main/java/com/example/antiaircraftgun/SimpleMap.java @@ -0,0 +1,42 @@ +package com.example.antiaircraftgun; + +import javafx.scene.canvas.GraphicsContext; +import javafx.scene.paint.Color; + +public class SimpleMap extends AbstractMap { + protected void DrawBarrierPart(GraphicsContext gc, int i, int j) + { + gc.setFill(Color.BLACK); + gc.fillRect(i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1)); + } + protected void DrawRoadPart(GraphicsContext gc, int i, int j) + { + gc.setFill(Color.LIGHTGRAY); + gc.fillRect(i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1)); + } + + protected void GenerateMap() + { + _map = new int[100][100]; + _size_x = (float)_width / _map.length; + _size_y = (float)_height / _map[0].length; + int counter = 0; + for (int i = 0; i < _map.length; ++i) + { + for (int j = 0; j < _map[0].length; ++j) + { + _map[i][j] = _freeRoad; + } + } + while (counter < 50) + { + int x = _random.nextInt(0, 100); + int y = _random.nextInt(0, 100); + if (_map[x][y] == _freeRoad) + { + _map[x][y] = _barrier; + counter++; + } + } + } +} diff --git a/AntiAircraftGun/src/main/java/com/example/antiaircraftgun/TrainingGroundMap.java b/AntiAircraftGun/src/main/java/com/example/antiaircraftgun/TrainingGroundMap.java new file mode 100644 index 0000000..2faf3b7 --- /dev/null +++ b/AntiAircraftGun/src/main/java/com/example/antiaircraftgun/TrainingGroundMap.java @@ -0,0 +1,42 @@ +package com.example.antiaircraftgun; + +import javafx.scene.canvas.GraphicsContext; +import javafx.scene.paint.Color; + +public class TrainingGroundMap extends AbstractMap{ + protected void DrawBarrierPart(GraphicsContext gc, int i, int j) + { + gc.setFill(Color.BLACK); + gc.fillRect(i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1)); + } + protected void DrawRoadPart(GraphicsContext gc, int i, int j) + { + gc.setFill(Color.LIGHTGREEN); + gc.fillRect(i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1)); + } + + protected void GenerateMap() + { + _map = new int[100][100]; + _size_x = (float)_width / _map.length; + _size_y = (float)_height / _map[0].length; + int counter = 0; + for (int i = 0; i < _map.length; ++i) + { + for (int j = 0; j < _map[0].length; ++j) + { + _map[i][j] = _freeRoad; + } + } + while (counter < 25) + { + int x = _random.nextInt(0, 100); + int y = _random.nextInt(0, 100); + if (_map[x][y] == _freeRoad) + { + _map[x][y] = _barrier; + counter++; + } + } + } +} diff --git a/AntiAircraftGun/src/main/resources/com/example/antiaircraftgun/form-armored-vehicle-view.fxml b/AntiAircraftGun/src/main/resources/com/example/antiaircraftgun/form-armored-vehicle-view.fxml new file mode 100644 index 0000000..505116d --- /dev/null +++ b/AntiAircraftGun/src/main/resources/com/example/antiaircraftgun/form-armored-vehicle-view.fxml @@ -0,0 +1,96 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/AntiAircraftGun/src/main/resources/com/example/antiaircraftgun/form-map-view.fxml b/AntiAircraftGun/src/main/resources/com/example/antiaircraftgun/form-map-view.fxml new file mode 100644 index 0000000..f267870 --- /dev/null +++ b/AntiAircraftGun/src/main/resources/com/example/antiaircraftgun/form-map-view.fxml @@ -0,0 +1,104 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/AntiAircraftGun/src/main/resources/com/example/antiaircraftgun/hello-view.fxml b/AntiAircraftGun/src/main/resources/com/example/antiaircraftgun/hello-view.fxml deleted file mode 100644 index af7d531..0000000 --- a/AntiAircraftGun/src/main/resources/com/example/antiaircraftgun/hello-view.fxml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - -- 2.25.1