diff --git a/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/AbstractMap.java b/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/AbstractMap.java index f32ddc8..a8233ac 100644 --- a/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/AbstractMap.java +++ b/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/AbstractMap.java @@ -1,11 +1,9 @@ package com.example.pibd22_kalyshev_y_v_motorboat_hard; import javafx.scene.canvas.GraphicsContext; - import java.util.Random; -public abstract class AbstractMap -{ +public abstract class AbstractMap { private IDrawningObject _drawningObject = null; private GraphicsContext _graphicsContext = null; protected int[][] _map = null; @@ -16,26 +14,20 @@ public abstract class AbstractMap protected final Random _random = new Random(); protected final int _freeRoad = 0; protected final int _barrier = 1; - - public void CreateMap(int width, int height, IDrawningObject drawningObject, GraphicsContext gc) - { + public void CreateMap(int width, int height, IDrawningObject drawningObject, GraphicsContext gc) { _width = width; _height = height; _drawningObject = drawningObject; _graphicsContext = gc; GenerateMap(); - while (!SetObjectOnMap()) - { + while (!SetObjectOnMap()) { GenerateMap(); } DrawMapWithObject(); } - - public void MoveObject(Direction direction) - { + public void MoveObject(Direction direction) { boolean enoughPlace = false; - switch (direction) - { + switch (direction) { case Up: enoughPlace = CheckEnoughPlace(0, (_drawningObject.GetStep() + 30) * -1); break; @@ -49,34 +41,25 @@ public abstract class AbstractMap enoughPlace = CheckEnoughPlace(_drawningObject.GetStep(), 0); break; } - if (enoughPlace) - { + if (enoughPlace) { _drawningObject.MoveObject(direction); } DrawMapWithObject(); } - - private boolean SetObjectOnMap() - { - if (_drawningObject == null || _map == null) - { + private boolean SetObjectOnMap() { + if (_drawningObject == null || _map == null) { return false; } int x = _random.nextInt(10); int y = _random.nextInt(50); _drawningObject.SetObject(x, y, _width, _height); - - while (!CheckEnoughPlace(0, -40)) - { + while (!CheckEnoughPlace(0, -40)) { x += 10; - if (x >= _width) - { - if (y <= _height) - { + if (x >= _width) { + if (y <= _height) { y += 10; x = 0; - } else - { + } else { return false; } } @@ -84,25 +67,17 @@ public abstract class AbstractMap } return true; } - private boolean CheckEnoughPlace(float x, float y) - { + private boolean CheckEnoughPlace(float x, float y) { float[] position = _drawningObject.GetCurrentPosition(); float right = (position[2] + x) / _size_x > 0 ? (position[2] + x) / _size_x : 0; float left = (position[0] + x) / _size_x > 0 ? (position[0] + x) / _size_x : 0; float up = (position[1] + y) / _size_y > 0 ? (position[1] + y) / _size_y : 0; float down = (position[3] + y) / _size_y > 0 ? (position[3] + y) / _size_y : 0; - /*float right = (_map[0].length * (position[2] + x)) / _width > 0 ? (_map[0].length * (position[2] + x)) / _width : 0; - float left = (_map[0].length * (position[0] + x)) / _width > 0 ? (_map[0].length * (position[0] + x)) / _width : 0; - float up = (_map.length * (position[1] + y)) / _height > 0 ? (_map.length * (position[1] + y)) / _height : 0; - float down = (_map.length * (position[3] + y)) / _height > 0 ? (_map.length * (position[3] + y)) / _height : 0;*/ if (position[3] + y > _height || position[2] + x > _width || position[1] + y < 0 || position[0] + x < 0) return false; - for (float i = left; i <= right; i+=0.5) - { - for (float j = up; j <= down; j+=0.5) - { - if (_map[Math.round(i)][Math.round(j)] == _barrier) - { + for (float i = left; i <= right; i+=0.5) { + for (float j = up; j <= down; j+=0.5) { + if (_map[Math.round(i)][Math.round(j)] == _barrier) { return false; } } @@ -110,23 +85,17 @@ public abstract class AbstractMap return true; } - public void DrawMapWithObject() - { - if (_drawningObject == null || _map == null) - { + public void DrawMapWithObject() { + if (_drawningObject == null || _map == null) { return; } - for (int i = 0; i < _map.length; i++) - { - for (int j = 0; j < _map[i].length; j++) - { - if (_map[i][j] == _freeRoad) - { + for (int i = 0; i < _map.length; i++) { + for (int j = 0; j < _map[i].length; j++) { + if (_map[i][j] == _freeRoad) { DrawRoadPart(_graphicsContext, i, j); } - else if (_map[i][j] == _barrier) - { + else if (_map[i][j] == _barrier) { DrawBarrierPart(_graphicsContext, i, j); } } diff --git a/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/ControllerBoat.java b/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/ControllerBoat.java index 5054bc8..27659c7 100644 --- a/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/ControllerBoat.java +++ b/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/ControllerBoat.java @@ -43,14 +43,11 @@ public class ControllerBoat { private Button buttonDown; private final double rootPadding = 10.0; private DrawningBoat _boat; - @FXML - public void initialize() - { + public void initialize() { buttonCreate.setTranslateX(rootPadding); - root.widthProperty().addListener((obs, oldVal, newVal) -> - { + root.widthProperty().addListener((obs, oldVal, newVal) -> { UpdateGUI(); if (_boat != null) { @@ -58,30 +55,24 @@ public class ControllerBoat { } Draw(); }); - root.heightProperty().addListener((obs, oldVal, newVal) -> - { + root.heightProperty().addListener((obs, oldVal, newVal) -> { UpdateGUI(); - if (_boat != null) - { + if (_boat != null) { _boat.ChangeBorders((int) canvas.getWidth(), (int) canvas.getHeight()); } Draw(); }); } - @FXML - void ButtonCreate_Click() - { + void ButtonCreate_Click() { Random rnd = new Random(); _boat = new DrawningBoat(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() - { + void ButtonCreateModif_Click() { Random rnd = new Random(); _boat = new DrawningSpeedboat(rnd.nextInt(200) + 100, rnd.nextInt(1000) + 1000, Color.rgb(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)), @@ -90,17 +81,13 @@ public class ControllerBoat { SetData(); Draw(); } - @FXML - void ButtonMove_Click(ActionEvent event) - { - if (_boat == null) - { + void ButtonMove_Click(ActionEvent event) { + if (_boat == null) { return; } String buttonName = ((Button) event.getSource()).getId(); - switch (buttonName) - { + switch (buttonName) { case "buttonUp" -> _boat.MoveTransport(Direction.Up); case "buttonDown" -> _boat.MoveTransport(Direction.Down); case "buttonLeft" -> _boat.MoveTransport(Direction.Left); @@ -108,48 +95,35 @@ public class ControllerBoat { } Draw(); } - @FXML - private void ComboBoxOrnamentType_Changed() - { - if (_boat != null) - { + private void ComboBoxOrnamentType_Changed() { + if (_boat != null) { ChangeDrawningOars(); Draw(); } } - @FXML - private void ComboBoxNumOfRollers_Changed() - { - if (_boat != null) - { + private void ComboBoxNumOfRollers_Changed() { + if (_boat != null) { _boat.GetDrawningOars().SetNumberOars(Integer.parseInt(comboBoxNumOars.getValue())); Draw(); } } - - private void ChangeDrawningOars() - { - if (_boat != null) - { - IDrawningAdditionalElement newDrawningOars = switch (comboBoxOarsType.getValue()) - { + private void ChangeDrawningOars() { + if (_boat != null) { + IDrawningAdditionalElement newDrawningOars = switch (comboBoxOarsType.getValue()) { case "None" -> new DrawningOars(_boat.GetBoat().GetBodyColor()); case "Slim" -> new DrawningSlimOars(_boat.GetBoat().GetBodyColor()); case "Large" -> new DrawningLargeOars(_boat.GetBoat().GetBodyColor()); default -> null; }; - if (newDrawningOars != null) - { + if (newDrawningOars != null) { _boat.SetDrawningOars(newDrawningOars); _boat.GetDrawningOars().SetNumberOars(Integer.parseInt(comboBoxNumOars.getValue())); } } } - - private void UpdateGUI() - { + private void UpdateGUI() { double rootWidth = root.getWidth(); double rootHeight = root.getHeight(); @@ -180,9 +154,7 @@ public class ControllerBoat { buttonRight.setTranslateY(rootHeight - flowPaneHeight - buttonMoveSize - rootPadding); buttonRight.setTranslateX(rootWidth - rootPadding - buttonMoveSize); } - - private void Draw() - { + private void Draw() { GraphicsContext gc = canvas.getGraphicsContext2D(); gc.clearRect(0.0, 0.0, canvas.getWidth(), canvas.getHeight()); @@ -193,14 +165,11 @@ public class ControllerBoat { gc.setLineWidth(4); gc.strokeRect(0.0, 0.0, canvas.getWidth(), canvas.getHeight()); - if (_boat != null) - { + if (_boat != null) { _boat.DrawTransport(gc); } } - - private void SetData() - { + private void SetData() { ChangeDrawningOars(); Random rnd = new Random(); _boat.SetPosition(rnd.nextInt(90) + 10, rnd.nextInt(90), diff --git a/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/ControllerMap.java b/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/ControllerMap.java index 5232535..472b628 100644 --- a/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/ControllerMap.java +++ b/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/ControllerMap.java @@ -13,8 +13,7 @@ import javafx.scene.paint.Color; import java.util.Random; -public class ControllerMap -{ +public class ControllerMap { @FXML private Pane root; @FXML @@ -47,42 +46,32 @@ public class ControllerMap private Button buttonDown; private final double buttonMargin = 10.0; private AbstractMap _abstractMap; - @FXML - public void initialize() - { + public void initialize() { buttonCreate.setTranslateX(buttonMargin); - root.widthProperty().addListener((obs, oldVal, newVal) -> - { + root.widthProperty().addListener((obs, oldVal, newVal) -> { UpdateGUI(); - if (_abstractMap != null) - { + if (_abstractMap != null) { _abstractMap.DrawMapWithObject(); } }); - root.heightProperty().addListener((obs, oldVal, newVal) -> - { + root.heightProperty().addListener((obs, oldVal, newVal) -> { UpdateGUI(); - if (_abstractMap != null) - { + if (_abstractMap != null) { _abstractMap.DrawMapWithObject(); } }); } - @FXML - void ButtonCreate_Click() - { + void ButtonCreate_Click() { Random rnd = new Random(); DrawningBoat boat = new DrawningBoat(rnd.nextInt(200) + 100, rnd.nextInt(1000) + 1000, Color.rgb(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256))); SetData(boat); } - @FXML - void ButtonCreateModif_Click() - { + void ButtonCreateModif_Click() { Random rnd = new Random(); DrawningSpeedboat boat = new DrawningSpeedboat(rnd.nextInt(200) + 100, rnd.nextInt(1000) + 1000, Color.rgb(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)), @@ -90,52 +79,39 @@ public class ControllerMap (rnd.nextInt(2) != 0), (rnd.nextInt(2) != 0), (rnd.nextInt(2) != 0)); SetData(boat); } - @FXML - void ButtonMove_Click(ActionEvent event) - { - if (_abstractMap == null) - { + void ButtonMove_Click(ActionEvent event) { + if (_abstractMap == null) { return; } String buttonName = ((Button) event.getSource()).getId(); - switch (buttonName) - { + 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()) - { + private void ComboBoxSelectorMap_Changed() { + switch (comboBoxSelectorMap.getValue()) { case "Simple map" -> _abstractMap = new SimpleMap(); case "My second map" -> _abstractMap = new MySecondMap(); } } - - private void ChangeDrawningOars(DrawningBoat boat) - { - IDrawningAdditionalElement newDrawningOars = switch (comboBoxOarsType.getValue()) - { + private void ChangeDrawningOars(DrawningBoat boat) { + IDrawningAdditionalElement newDrawningOars = switch (comboBoxOarsType.getValue()) { case "None" -> new DrawningOars(boat.GetBoat().GetBodyColor()); case "Slim" -> new DrawningSlimOars(boat.GetBoat().GetBodyColor()); case "Large" -> new DrawningLargeOars(boat.GetBoat().GetBodyColor()); default -> null; }; - if (newDrawningOars != null) - { + if (newDrawningOars != null) { boat.SetDrawningOars(newDrawningOars); boat.GetDrawningOars().SetNumberOars(Integer.parseInt(comboBoxNumOars.getValue())); } } - - private void UpdateGUI() - { + private void UpdateGUI() { double sceneWidth = root.getWidth(); double sceneHeight = root.getHeight(); @@ -152,8 +128,7 @@ public class ControllerMap int buttonMoveHeight = 30; int distanceBetweenMoveButtons = 5; - buttonUp.setTranslateY(sceneHeight - flowPaneHeight - buttonMoveHeight * 2.0 - buttonMargin - - distanceBetweenMoveButtons); + buttonUp.setTranslateY(sceneHeight - flowPaneHeight - buttonMoveHeight * 2.0 - buttonMargin - distanceBetweenMoveButtons); int buttonMoveWidth = 30; buttonUp.setTranslateX(sceneWidth - buttonMargin - buttonMoveWidth * 2.0 - distanceBetweenMoveButtons); @@ -161,15 +136,12 @@ public class ControllerMap buttonDown.setTranslateX(sceneWidth- buttonMargin - buttonMoveWidth * 2.0 - distanceBetweenMoveButtons); buttonLeft.setTranslateY(sceneHeight - flowPaneHeight - buttonMoveHeight - buttonMargin); - buttonLeft.setTranslateX(sceneWidth - buttonMargin - buttonMoveWidth * 3.0 - - distanceBetweenMoveButtons * 2.0); + buttonLeft.setTranslateX(sceneWidth - buttonMargin - buttonMoveWidth * 3.0 - distanceBetweenMoveButtons * 2.0); buttonRight.setTranslateY(sceneHeight - flowPaneHeight - buttonMoveHeight - buttonMargin); buttonRight.setTranslateX(sceneWidth - buttonMargin - buttonMoveWidth); } - - private void SetData(DrawningBoat boat) - { + private void SetData(DrawningBoat boat) { ChangeDrawningOars(boat); labelSpeedValue.setText(Integer.toString(boat.GetBoat().GetSpeed())); labelWeightValue.setText(Double.toString(boat.GetBoat().GetWeight())); diff --git a/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/Direction.java b/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/Direction.java index 13232de..3754719 100644 --- a/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/Direction.java +++ b/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/Direction.java @@ -5,11 +5,8 @@ public enum Direction { Down, Left, Right; - - public static Direction FromInteger(int intValue) - { - switch(intValue) - { + public static Direction FromInteger(int intValue) { + switch(intValue) { case 1: return Up; case 2: diff --git a/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/DrawningBoat.java b/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/DrawningBoat.java index babfcc1..ec9c70f 100644 --- a/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/DrawningBoat.java +++ b/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/DrawningBoat.java @@ -3,8 +3,7 @@ package com.example.pibd22_kalyshev_y_v_motorboat_hard; import javafx.scene.canvas.GraphicsContext; import javafx.scene.paint.Color; -public class DrawningBoat -{ +public class DrawningBoat { private EntityBoat _boat; private IDrawningAdditionalElement _drawningOars; protected float _startPosX; @@ -13,7 +12,6 @@ public class DrawningBoat private Integer _pictureHeight; private int _boatWidth = 170; private int _boatHeight = 60; - public EntityBoat GetBoat() { return _boat; @@ -22,84 +20,67 @@ public class DrawningBoat { _boat = boat; } - public IDrawningAdditionalElement GetDrawningOars() - { + public IDrawningAdditionalElement GetDrawningOars() { return _drawningOars; } public void SetDrawningOars(IDrawningAdditionalElement drawningOars) { _drawningOars = drawningOars; } - public DrawningBoat(int speed, float weight, Color bodyColor) - { + public DrawningBoat(int speed, float weight, Color bodyColor) { _boat = new EntityBoat(speed, weight, bodyColor); _drawningOars = new DrawningOars(bodyColor); } - protected DrawningBoat(int speed, float weight, Color bodyColor, int boatWidth, int boatHeight) - { + protected DrawningBoat(int speed, float weight, Color bodyColor, int boatWidth, int boatHeight) { this(speed, weight, bodyColor); _boatHeight = boatHeight; _boatWidth = boatWidth; } - public void SetPosition(int x, int y, int width, int height) - { + public void SetPosition(int x, int y, int width, int height) { if (x < 0 || y < 0) { return; } - if (x + _boatWidth > width || y + _drawningOars.deltaYdown + _boatHeight > height) { return; } - _startPosX = x; _startPosY = y; - _pictureWidth = width; _pictureHeight = height; } - - public void MoveTransport(Direction direction) - { + public void MoveTransport(Direction direction) { if (_pictureWidth == null || _pictureHeight == null) { return; } - switch (direction) { case Up: if (_startPosY - _boat.GetStep() - _drawningOars.deltaYup > 0) { _startPosY -= _boat.GetStep(); } break; - case Down: if (_startPosY + _boatHeight + _boat.GetStep() + _drawningOars.deltaYdown < _pictureHeight) { _startPosY += _boat.GetStep(); } break; - case Left: if (_startPosX - _boat.GetStep() > 0) { _startPosX -= _boat.GetStep(); } break; - case Right: if (_startPosX + _boatWidth + _boat.GetStep() < _pictureWidth) { _startPosX += _boat.GetStep(); } break; - default: break; } } - - public void DrawTransport(GraphicsContext gc) - { + public void DrawTransport(GraphicsContext gc) { if (_startPosX < 0 || _startPosY < 0 || _pictureWidth == null || _pictureHeight == null) { return; } - _startPosY += 40; // Корпус gc.setStroke(Color.BLACK); @@ -109,7 +90,6 @@ public class DrawningBoat new double[] {_startPosY, _startPosY, _startPosY+30, _startPosY+60, _startPosY+60, _startPosY}, 6); gc.strokePolyline(new double[] {_startPosX, _startPosX+120, _startPosX+170, _startPosX+120, _startPosX, _startPosX}, new double[] {_startPosY, _startPosY, _startPosY+30, _startPosY+60, _startPosY+60, _startPosY}, 6); - // Седло gc.setFill(Color.BROWN); gc.fillOval(_startPosX+10, _startPosY+10, 110, 40); @@ -117,28 +97,22 @@ public class DrawningBoat _drawningOars.DrawOars(gc, _startPosX, _startPosY); } - - public void ChangeBorders(int width, int height) - { + public void ChangeBorders(int width, int height) { _pictureWidth = width; _pictureHeight = height; - if (_pictureWidth <= _boatWidth || _pictureHeight <= _boatHeight) { _pictureWidth = null; _pictureHeight = null; return; } - if (_startPosX + _boatWidth > _pictureWidth) { _startPosX = _pictureWidth - _boatWidth; } - if (_startPosY + _boatHeight > _pictureHeight) { _startPosY = _pictureHeight - _boatHeight; } } - public float[] GetCurrentPosition() - { + public float[] GetCurrentPosition() { float[] position = new float[4]; position[0] = _startPosX; position[1] = _startPosY; diff --git a/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/DrawningLargeOars.java b/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/DrawningLargeOars.java index 693cc72..2220374 100644 --- a/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/DrawningLargeOars.java +++ b/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/DrawningLargeOars.java @@ -6,8 +6,7 @@ import javafx.scene.paint.Color; public class DrawningLargeOars implements IDrawningAdditionalElement { private Color _OarsColor; private NumberOars _numOars; - public void SetNumberOars(int numberOars) - { + public void SetNumberOars(int numberOars) { _numOars = NumberOars.FromInteger(numberOars); } public int deltaYdown = 0; @@ -29,14 +28,12 @@ public class DrawningLargeOars implements IDrawningAdditionalElement { deltaYup = 80; deltaYdown = 80; break; - case Two: DrawOar1(gc, startPosX, startPosY); DrawOar2(gc, startPosX, startPosY); deltaYup = 80; deltaYdown = 80; break; - case Three: DrawOar1(gc, startPosX, startPosY); DrawOar2(gc, startPosX, startPosY); diff --git a/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/DrawningOars.java b/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/DrawningOars.java index 4a9b7c7..d017864 100644 --- a/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/DrawningOars.java +++ b/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/DrawningOars.java @@ -6,8 +6,7 @@ import javafx.scene.paint.Color; public class DrawningOars implements IDrawningAdditionalElement{ private Color _OarsColor; private NumberOars _numOars; - public void SetNumberOars(int numberOars) - { + public void SetNumberOars(int numberOars) { _numOars = NumberOars.FromInteger(numberOars); } public int deltaYdown = 0; diff --git a/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/DrawningObjectBoat.java b/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/DrawningObjectBoat.java index 540323f..dcd6573 100644 --- a/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/DrawningObjectBoat.java +++ b/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/DrawningObjectBoat.java @@ -9,18 +9,14 @@ public class DrawningObjectBoat implements IDrawningObject { _boat = boat; } public IDrawningAdditionalElement GetDrawningOars() {return _boat.GetDrawningOars();} - public float GetStep() - { - if (_boat != null && _boat.GetBoat() != null) - { + public float GetStep() { + if (_boat != null && _boat.GetBoat() != null) { return _boat.GetBoat().GetStep(); } return 0F; } - public float[] GetCurrentPosition() - { - if (_boat != null) - { + public float[] GetCurrentPosition() { + if (_boat != null) { return _boat.GetCurrentPosition(); } return new float[4]; @@ -33,12 +29,9 @@ public class DrawningObjectBoat implements IDrawningObject { { _boat.SetPosition(x, y, width, height); } - public void DrawningObject(GraphicsContext gc) - { - if (_boat != null) - { + public void DrawningObject(GraphicsContext gc) { + if (_boat != null) { _boat.DrawTransport(gc); } } - } \ No newline at end of file diff --git a/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/DrawningSlimOars.java b/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/DrawningSlimOars.java index fdb6d9e..64122e2 100644 --- a/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/DrawningSlimOars.java +++ b/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/DrawningSlimOars.java @@ -29,14 +29,12 @@ public class DrawningSlimOars implements IDrawningAdditionalElement { deltaYup = 80; deltaYdown = 80; break; - case Two: DrawOar1(gc, startPosX, startPosY); DrawOar2(gc, startPosX, startPosY); deltaYup = 80; deltaYdown = 80; break; - case Three: DrawOar1(gc, startPosX, startPosY); DrawOar2(gc, startPosX, startPosY); diff --git a/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/DrawningSpeedboat.java b/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/DrawningSpeedboat.java index 05a44cc..0d69dd3 100644 --- a/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/DrawningSpeedboat.java +++ b/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/DrawningSpeedboat.java @@ -3,18 +3,14 @@ package com.example.pibd22_kalyshev_y_v_motorboat_hard; import javafx.scene.canvas.GraphicsContext; import javafx.scene.paint.Color; -public class DrawningSpeedboat extends DrawningBoat -{ - public DrawningSpeedboat(int speed, float weight, Color bodyColor, Color dopColor, boolean bodyKit, boolean wing, boolean sportLine) - { +public class DrawningSpeedboat extends DrawningBoat { + public DrawningSpeedboat(int speed, float weight, Color bodyColor, Color dopColor, boolean bodyKit, boolean wing, boolean sportLine) { super(speed, weight, bodyColor, 195, 80); SetBoat(new EntitySpeedboat(speed, weight, bodyColor, dopColor, bodyKit, wing, sportLine)); } @Override - public void DrawTransport(GraphicsContext gc) - { - if (!(GetBoat() instanceof EntitySpeedboat speedboat)) - { + public void DrawTransport(GraphicsContext gc) { + if (!(GetBoat() instanceof EntitySpeedboat speedboat)) { return; } @@ -27,8 +23,7 @@ public class DrawningSpeedboat extends DrawningBoat _startPosX -= 25; _startPosY += 30; - if (speedboat.GetWing()) - { + if (speedboat.GetWing()) { gc.setFill(speedboat.GetDopColor()); gc.fillRect(_startPosX, _startPosY, 20, 80); gc.strokeRect(_startPosX, _startPosY, 20, 80); @@ -38,8 +33,7 @@ public class DrawningSpeedboat extends DrawningBoat } _startPosX += 25; _startPosY += 10; - if (speedboat.GetBodyKit()) - { + if (speedboat.GetBodyKit()) { double[] bodyKitX = { _startPosX + 120, _startPosX + 155, @@ -59,8 +53,7 @@ public class DrawningSpeedboat extends DrawningBoat gc.setFill(speedboat.GetDopColor()); gc.fillPolygon(bodyKitX, bodyKitY, 6); } - if (speedboat.GetSportLine()) - { + if (speedboat.GetSportLine()) { double[] sportLineX = { _startPosX + 70, _startPosX + 80, diff --git a/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/EntityBoat.java b/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/EntityBoat.java index 768cdbb..a6b351d 100644 --- a/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/EntityBoat.java +++ b/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/EntityBoat.java @@ -3,8 +3,7 @@ package com.example.pibd22_kalyshev_y_v_motorboat_hard; import javafx.scene.paint.Color; import java.util.Random; -public class EntityBoat -{ +public class EntityBoat { private int _speed; private float _weight; private Color _bodyColor; @@ -12,24 +11,19 @@ public class EntityBoat { return _speed; } - public float GetWeight() { return _weight; } - public Color GetBodyColor() { return _bodyColor; } - public float GetStep() { return _speed * 100 / _weight; } - - public EntityBoat(int speed, float weight, Color bodyColor) - { + public EntityBoat(int speed, float weight, Color bodyColor) { Random random = new Random(); _speed = speed <= 0 ? random.nextInt(5) + 25 : speed; _weight = weight <= 0 ? random.nextInt(30) + 70 : weight; diff --git a/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/EntitySpeedboat.java b/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/EntitySpeedboat.java index 3a859b8..07bea1a 100644 --- a/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/EntitySpeedboat.java +++ b/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/EntitySpeedboat.java @@ -2,8 +2,7 @@ package com.example.pibd22_kalyshev_y_v_motorboat_hard; import javafx.scene.paint.Color; -public class EntitySpeedboat extends EntityBoat -{ +public class EntitySpeedboat extends EntityBoat { private final Color _dopColor; private final boolean _bodyKit; private final boolean _wing; @@ -20,9 +19,7 @@ public class EntitySpeedboat extends EntityBoat public boolean GetSportLine() { return _sportLine; } - - public EntitySpeedboat(int speed, float weight, Color bodyColor, Color dopColor, boolean bodyKit, boolean wing, boolean sportLine) - { + public EntitySpeedboat(int speed, float weight, Color bodyColor, Color dopColor, boolean bodyKit, boolean wing, boolean sportLine) { super(speed, weight, bodyColor); _dopColor = dopColor; _bodyKit = bodyKit; diff --git a/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/FormBoat.java b/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/FormBoat.java index 98108cf..7cf1625 100644 --- a/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/FormBoat.java +++ b/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/FormBoat.java @@ -11,11 +11,9 @@ import javafx.stage.Stage; import java.io.IOException; -public class FormBoat extends Application -{ +public class FormBoat extends Application { @Override - public void start(Stage stage) throws IOException - { + public void start(Stage stage) throws IOException { FXMLLoader fxmlLoader = new FXMLLoader(FormBoat.class.getResource("form-boat-view.fxml")); Scene scene = new Scene(fxmlLoader.load(), 320, 240); @@ -25,9 +23,7 @@ public class FormBoat extends Application FirstUpdateGUI(scene); stage.show(); } - - private void FirstUpdateGUI(Scene scene) - { + private void FirstUpdateGUI(Scene scene) { Pane root = (Pane)scene.lookup("#root"); Canvas canvas = (Canvas)scene.lookup("#canvas"); Button buttonCreate = (Button)scene.lookup("#buttonCreate"); diff --git a/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/FormMap.java b/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/FormMap.java index 08ab726..13461d7 100644 --- a/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/FormMap.java +++ b/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/FormMap.java @@ -11,11 +11,9 @@ import javafx.stage.Stage; import java.io.IOException; -public class FormMap extends Application -{ +public class FormMap extends Application { @Override - public void start(Stage stage) throws IOException - { + public void start(Stage stage) throws IOException { FXMLLoader fxmlLoader = new FXMLLoader(FormMap.class.getResource("form-map-view.fxml")); Scene scene = new Scene(fxmlLoader.load(), 800, 800); @@ -26,8 +24,7 @@ public class FormMap extends Application stage.show(); } - private void FirstUpdateGUI(Scene scene) - { + private void FirstUpdateGUI(Scene scene) { Pane root = (Pane)scene.lookup("#root"); Canvas canvas = (Canvas)scene.lookup("#canvas"); Button buttonCreate = (Button)scene.lookup("#buttonCreate"); @@ -71,7 +68,6 @@ public class FormMap extends Application buttonRight.setTranslateY(rootHeight - flowPaneHeight - buttonMoveSize - rootPadding); buttonRight.setTranslateX(rootWidth - rootPadding - buttonMoveSize); } - public static void main(String[] args) { launch(); diff --git a/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/IDrawningAdditionalElement.java b/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/IDrawningAdditionalElement.java index a81cd2f..7126aed 100644 --- a/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/IDrawningAdditionalElement.java +++ b/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/IDrawningAdditionalElement.java @@ -2,8 +2,7 @@ package com.example.pibd22_kalyshev_y_v_motorboat_hard; import javafx.scene.canvas.GraphicsContext; -public interface IDrawningAdditionalElement -{ +public interface IDrawningAdditionalElement { public int deltaYdown = 0; public int deltaYup = 0; public void SetNumberOars(int numberOars); diff --git a/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/IDrawningObject.java b/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/IDrawningObject.java index d9174c9..8df045a 100644 --- a/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/IDrawningObject.java +++ b/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/IDrawningObject.java @@ -2,8 +2,7 @@ package com.example.pibd22_kalyshev_y_v_motorboat_hard; import javafx.scene.canvas.GraphicsContext; -public interface IDrawningObject -{ +public interface IDrawningObject { public float GetStep(); public IDrawningAdditionalElement GetDrawningOars(); public void SetObject(int x, int y, int width, int height); diff --git a/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/MySecondMap.java b/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/MySecondMap.java index 2613f81..22cc503 100644 --- a/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/MySecondMap.java +++ b/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/MySecondMap.java @@ -3,19 +3,15 @@ package com.example.pibd22_kalyshev_y_v_motorboat_hard; import javafx.scene.canvas.GraphicsContext; import javafx.scene.paint.Color; -public class MySecondMap extends AbstractMap -{ - protected void DrawBarrierPart(GraphicsContext gc, int i, int j) - { +public class MySecondMap extends AbstractMap { + protected void DrawBarrierPart(GraphicsContext gc, int i, int j) { gc.setFill(Color.RED); 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) - { + protected void DrawRoadPart(GraphicsContext gc, int i, int j) { gc.setFill(Color.rgb(242, 242, 242)); gc.fillRect(i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1)); } - protected void GenerateMap() { _map = new int[150][100]; _size_x = (float)_width / _map.length; diff --git a/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/NumberOars.java b/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/NumberOars.java index 26cb2f4..8d6431b 100644 --- a/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/NumberOars.java +++ b/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/NumberOars.java @@ -5,20 +5,14 @@ public enum NumberOars One, Two, Three; - - public static NumberOars FromInteger(int intValue) - { - switch(intValue) - { + public static NumberOars FromInteger(int intValue) { + switch(intValue) { case 1: return One; - case 2: return Two; - case 3: return Three; - default: System.out.println("Error: incorrect value for enum"); return One; diff --git a/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/SimpleMap.java b/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/SimpleMap.java index 472082c..05c86d0 100644 --- a/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/SimpleMap.java +++ b/src/main/java/com/example/pibd22_kalyshev_y_v_motorboat_hard/SimpleMap.java @@ -3,37 +3,29 @@ package com.example.pibd22_kalyshev_y_v_motorboat_hard; import javafx.scene.canvas.GraphicsContext; import javafx.scene.paint.Color; -public class SimpleMap extends AbstractMap -{ - protected void DrawBarrierPart(GraphicsContext gc, int i, int j) - { +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) - { + protected void DrawRoadPart(GraphicsContext gc, int i, int j) { gc.setFill(Color.GRAY); gc.fillRect(i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1)); } - protected void GenerateMap() - { + 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[i].length; ++j) - { + for (int i = 0; i < _map.length; ++i) { + for (int j = 0; j < _map[i].length; ++j) { _map[i][j] = _freeRoad; } } - while (counter < 50) - { + while (counter < 50) { int x = _random.nextInt(0, 100); int y = _random.nextInt(0, 100); - if (_map[x][y] == _freeRoad) - { + if (_map[x][y] == _freeRoad) { _map[x][y] = _barrier; counter++; }