diff --git a/.idea/dictionaries/zyzf.xml b/.idea/dictionaries/zyzf.xml new file mode 100644 index 0000000..0452418 --- /dev/null +++ b/.idea/dictionaries/zyzf.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file 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 3dc9eeb..d4f409f 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 @@ -33,125 +33,23 @@ public abstract class AbstractMap public void MoveObject(Direction direction) { - boolean roadIsClear = true; - - float[] position = _drawningObject.GetCurrentPosition(); - int xNumOfCells; - int yNumOfCells; - int xObjOffset; - int yObjOffset; - + boolean enoughPlace = false; switch (direction) { case Up: - xNumOfCells = (int)Math.ceil((position[2] - position[0]) / _size_x); - yNumOfCells = (int)Math.ceil(_drawningObject.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; - } - } - } + enoughPlace = CheckEnoughPlace(0, _drawningObject.GetStep() * -1); break; - case Down: - xNumOfCells = (int)Math.ceil((position[2] - position[0]) / _size_x); - yNumOfCells = (int)Math.ceil(_drawningObject.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; - } - } - } + enoughPlace = CheckEnoughPlace(0, _drawningObject.GetStep()); break; - case Left: - xNumOfCells = (int)Math.ceil(_drawningObject.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; - } - } - } + enoughPlace = CheckEnoughPlace(_drawningObject.GetStep() * -1, 0); break; - case Right: - xNumOfCells = (int)Math.ceil(_drawningObject.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; - } - } - } + enoughPlace = CheckEnoughPlace(_drawningObject.GetStep(), 0); break; } - if (roadIsClear) + if (enoughPlace) { _drawningObject.MoveObject(direction); } @@ -164,52 +62,46 @@ public abstract class AbstractMap { return false; } - int x = _random.nextInt(0, 10); - int y = _random.nextInt(0, 10); + int x = _random.nextInt(10); + int y = _random.nextInt(10); + _drawningObject.SetObject(x, y, _width, _height); - float[] position = _drawningObject.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 (!CheckEnoughPlace(0, 0)) { - while (x < _width - (position[2] - position[0])) + x += 10; + if (x >= _width) { - if (AreaIsFree(xNumOfCells, yNumOfCells, xObjOffset, yObjOffset)) + if (y <= _height) { - _drawningObject.SetObject(x, y, _width, _height); - return true; + y += 10; + x = 0; + } else + { + return false; } - x += (int)_size_x; - xObjOffset = (int)(x / _size_x); } - x = 0; - y += (int)_size_y; - yObjOffset = (int)(y / _size_y); + _drawningObject.SetObject(x, y, _width, _height); } - - return false; + return true; } - - private boolean AreaIsFree(int xNumOfCells, int yNumOfCells, int xObjOffset, int yObjOffset) + private boolean CheckEnoughPlace(float x, float y) { - for (int i = 0; i <= yNumOfCells; i++) + 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; + 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 (int j = 0; j <= xNumOfCells; j++) + for (float j = up; j <= down; j+=0.5) { - if (yObjOffset + i >= _map.length || xObjOffset + j >= _map[0].length) - { - return false; - } - if (_map[xObjOffset + j][yObjOffset + i] == _barrier) + if (_map[Math.round(i)][Math.round(j)] == _barrier) { return false; } } } - return true; } @@ -220,9 +112,9 @@ public abstract class AbstractMap return; } - for (int i = 0; i < _map.length; ++i) + for (int i = 0; i < _map.length; i++) { - for (int j = 0; j < _map[0].length; ++j) + for (int j = 0; j < _map[i].length; j++) { if (_map[i][j] == _freeRoad) { 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 999a976..2febc2c 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 @@ -2,11 +2,13 @@ package com.example.pibd22_kalyshev_y_v_motorboat_hard; import javafx.event.ActionEvent; import javafx.fxml.FXML; +import javafx.geometry.Insets; 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.Border; import javafx.scene.layout.FlowPane; import javafx.scene.layout.Pane; import javafx.scene.paint.Color; 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 daeb0a8..2f3ce3c 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 @@ -18,96 +18,66 @@ public class DrawningSpeedboat extends DrawningBoat return; } - _startPosX += 8; - _startPosY += 1; - super.DrawTransport(gc); - _startPosX -= 8; - _startPosY -= 1; - gc.setStroke(Color.BLACK); gc.setLineWidth(2); - if (speedboat.GetBodyKit()) - { - double[] turretX = - { - 31.0 + _startPosX, - 31.0 + _startPosX, - 45.0 + _startPosX, - 83.0 + _startPosX, - 97.0 + _startPosX, - 97.0 + _startPosX, - }; - - double[] turretY = - { - 24.0 + _startPosY, - 12.0 + _startPosY, - 2.0 + _startPosY, - 2.0 + _startPosY, - 12.0 + _startPosY, - 24.0 + _startPosY, - }; - - gc.setFill(speedboat.GetDopColor()); - gc.fillPolygon(turretX, turretY, 6); - gc.strokePolygon(turretX, turretY, 6); - gc.strokeRect(32 + _startPosX, 22 + _startPosY, 64, 2); - - double[] muzzleX = - { - 94 + _startPosX, - 84 + _startPosX, - 120 + _startPosX, - 120 + _startPosX, - }; - - double[] muzzleY = - { - 9 + _startPosY, - 3 + _startPosY, - 3 + _startPosY, - 9 + _startPosY, - }; - - gc.setFill(Color.rgb(109, 137, 165)); - gc.fillPolygon(muzzleX, muzzleY, 4); - gc.strokePolygon(muzzleX, muzzleY, 4); - gc.fillRect(120 + _startPosX, 2 + _startPosY, 16, 8); - gc.strokeRect(120 + _startPosX, 2 + _startPosY, 16, 8); - } - + _startPosX += 25; + _startPosY -= 30; + super.DrawTransport(gc); + _startPosX -= 25; + _startPosY += 30; if (speedboat.GetWing()) { - gc.moveTo(60 + _startPosX, 1 + _startPosY); - gc.lineTo(60 + _startPosX, 24 + _startPosY); - gc.closePath(); - gc.setFill(speedboat.GetDopColor()); - gc.fillRect(_startPosX, 2 + _startPosY, 58, 8); - gc.strokeRect(_startPosX, 2 + _startPosY, 58, 8); - gc.fillRect(_startPosX, 10 + _startPosY, 58, 8); - gc.strokeRect(_startPosX, 10 + _startPosY, 58, 8); - gc.fillRect(_startPosX, _startPosY, 6, 17); - gc.strokeRect(_startPosX, _startPosY, 6, 17); - - double[] batteryMoutX = - { - 24 + _startPosX, - 15 + _startPosX, - 58 + _startPosX, - 58 + _startPosX - }; - double[] batteryMoutY = - { - 24 + _startPosY, - 18 + _startPosY, - 18 + _startPosY, - 24 + _startPosY - }; - gc.setFill(Color.rgb(21, 39, 71)); - gc.fillPolygon(batteryMoutX, batteryMoutY, 4); - gc.strokePolygon(batteryMoutX, batteryMoutY, 4); + gc.fillRect(_startPosX, _startPosY, 20, 80); + gc.strokeRect(_startPosX, _startPosY, 20, 80); + gc.setFill(speedboat.GetBodyColor()); + gc.fillRect(_startPosX + 20, _startPosY + 20, 10, 40); + gc.strokeRect(_startPosX + 20, _startPosY + 20, 10, 40); } + _startPosX += 25; + _startPosY += 10; + if (speedboat.GetBodyKit()) + { + double[] bodyKitX = { + _startPosX + 120, + _startPosX + 155, + _startPosX + 120, + _startPosX + 120, + _startPosX + 145, + _startPosX + 120 + }; + double[] bodyKitY = { + _startPosY + 10, + _startPosY + 30, + _startPosY + 50, + _startPosY + 45, + _startPosY + 30, + _startPosY + 15 + }; + gc.setFill(speedboat.GetDopColor()); + gc.fillPolygon(bodyKitX, bodyKitY, 6); + } + if (speedboat.GetSportLine()) + { + double[] sportLineX = { + _startPosX + 70, + _startPosX + 80, + _startPosX + 120, + _startPosX + 110 + }; + double[] sportLineY = { + _startPosY, + _startPosY, + _startPosY + 60, + _startPosY + 60 + }; + gc.setFill(speedboat.GetDopColor()); + gc.fillPolygon(sportLineX, sportLineY, 4); + gc.setFill(Color.BROWN); + gc.fillOval(_startPosX + 10, _startPosY + 10, 110, 40); + } + _startPosX -= 25; + _startPosY -= 10; } } \ No newline at end of file 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 0a5471e..bcf0807 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 @@ -17,7 +17,7 @@ public class FormMap extends Application public void start(Stage stage) throws IOException { FXMLLoader fxmlLoader = new FXMLLoader(FormMap.class.getResource("form-map-view.fxml")); - Scene scene = new Scene(fxmlLoader.load(), 320, 240); + Scene scene = new Scene(fxmlLoader.load(), 400, 400); stage.setTitle("Map"); stage.setScene(scene); 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 9974f13..472082c 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 @@ -23,7 +23,7 @@ public class SimpleMap extends AbstractMap int counter = 0; for (int i = 0; i < _map.length; ++i) { - for (int j = 0; j < _map[0].length; ++j) + for (int j = 0; j < _map[i].length; ++j) { _map[i][j] = _freeRoad; } diff --git a/src/main/resources/com/example/pibd22_kalyshev_y_v_motorboat_hard/form-map-view.fxml b/src/main/resources/com/example/pibd22_kalyshev_y_v_motorboat_hard/form-map-view.fxml index dd71b9f..42917ea 100644 --- a/src/main/resources/com/example/pibd22_kalyshev_y_v_motorboat_hard/form-map-view.fxml +++ b/src/main/resources/com/example/pibd22_kalyshev_y_v_motorboat_hard/form-map-view.fxml @@ -1,18 +1,14 @@ - + + + + + + - - - - - - - - - - - + + - + - - + + @@ -72,31 +68,31 @@ - - - -