diff --git a/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/ControllerMap.java b/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/ControllerMap.java index 7a2ea31..41ff74a 100644 --- a/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/ControllerMap.java +++ b/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/ControllerMap.java @@ -112,6 +112,12 @@ public class ControllerMap{ statusWeight.setText("Вес: %s".formatted(bus.Bus.Weight)); statusColor.setText("Цвет: %s".formatted(bus.Bus.BodyColor)); GraphicsContext gc = canvasBus.getGraphicsContext2D(); + + switch (choiceMap.getValue()) { + case "Простая карта" -> _abstractMap = new SimpleMap(); + case "Водная карта" -> _abstractMap = new WaterMap(); + } + _abstractMap.CreateMap((int) pictureBoxBus.getWidth(), (int) pictureBoxBus.getHeight(), new DrawingObjectBus(bus), gc); } diff --git a/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/WaterMap.java b/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/WaterMap.java new file mode 100644 index 0000000..6d3e2b3 --- /dev/null +++ b/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/WaterMap.java @@ -0,0 +1,49 @@ +package com.example.doubledeckerbus; + +import javafx.scene.paint.Color; + +public class WaterMap extends AbstractMap{ + @Override + protected void GenerateMap() { + _map = new int[100][100]; + _size_x = (float)_width / _map.length; + _size_y = (float)_height / _map[0].length; + + for (int i = 0; i < _map.length; ++i) + { + for (int j = 0; j < _map[0].length; ++j) + { + _map[i][j] = _freeRoad; + } + } + + int counter = 0; + 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++; + } + } + } + + @Override + protected void DrawRoadPart(int i, int j) { + if (_random.nextInt(0,10) == 9) { + gc.setFill(Color.GREEN); + } + else { + gc.setFill(Color.LIGHTGREEN); + } + gc.fillRect(i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1)); + } + + @Override + protected void DrawBarrierPart(int i, int j) { + gc.setFill(Color.BLUE); + gc.fillRect(i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1)); + } +}