From 0df20f400884b13a83435001471e5ac2236dce1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B9=20=D0=9F=D0=BE=D0=BB?= =?UTF-8?q?=D0=B5=D0=B2=D0=BE=D0=B9?= Date: Sat, 8 Oct 2022 16:04:32 +0400 Subject: [PATCH] Added class SimpleMap --- SimpleMap.java | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 SimpleMap.java diff --git a/SimpleMap.java b/SimpleMap.java new file mode 100644 index 0000000..26db081 --- /dev/null +++ b/SimpleMap.java @@ -0,0 +1,40 @@ +import java.awt.*; +import java.util.Arrays; + +public class SimpleMap extends AbstractMap { + private final Color barrierColor = Color.black; + private final Color roadColor = Color.gray; + + @Override + protected void drawBarrierPart(Graphics2D g, int i, int j) { + g.setColor(barrierColor); + g.fillRect(i * (int) _size_x, j * (int) _size_y, i * ((int) _size_x + 1), j * ((int) _size_y + 1)); + } + + @Override + protected void drawRoadPart(Graphics2D g, int i, int j) { + g.setColor(roadColor); + g.fillRect(i * (int) _size_x, j * (int) _size_y, i * ((int) _size_x + 1), j * ((int) _size_y + 1)); + } + + @Override + protected void generateMap() { + _map = new int[100][100]; + _size_x = (float)_width / _map[0].length; + _size_y = (float)_height / _map.length; + int counter = 0; + for (int[] row : _map) { + Arrays.fill(row, _freeRoad); + } + while (counter < 50) + { + int x = _random.nextInt(0, 100); + int y = _random.nextInt(0, 100); + if (_map[y][x] == _freeRoad) + { + _map[y][x] = _barrier; + counter++; + } + } + } +}