From febb4eaa6badb225d669b0a1ab89e60452a7affc Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sat, 8 Oct 2022 19:10:38 +0400 Subject: [PATCH] Added & fixed SimpleMap --- SimpleMap.java | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 SimpleMap.java diff --git a/SimpleMap.java b/SimpleMap.java new file mode 100644 index 0000000..4311230 --- /dev/null +++ b/SimpleMap.java @@ -0,0 +1,49 @@ +import java.awt.*; + +public class SimpleMap extends AbstractMap{ + /// Цвет участка закрытого + private final Color barrierColor = Color.BLACK; + /// Цвет участка открытого + private final Color roadColor = Color.GRAY; + + @Override + protected void DrawBarrierPart(Graphics g, int i, int j) + { + g.setColor(barrierColor); + g.fillRect( (int)(i * _size_x), (int)(j * _size_y), (int)(i * (_size_x + + 1)), (int)(j * (_size_y + 1))); + } + + @Override + protected void DrawRoadPart(Graphics g, int i, int j) + { + g.setColor(roadColor); + g.fillRect( (int)(i * _size_x), (int)(j * _size_y), (int)(i * (_size_x + + 1)),(int)( j * (_size_y + 1))); + } + @Override + 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(100); + int y = _random.nextInt(100); + if (_map[x][y] == _freeRoad) + { + _map[x][y] = _barrier; + counter++; + } + } + } +}