LabWork2 PIbd-21 Zacharchenko #2
@ -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);
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user