From 25dad761456ef9e3d9b60d4e7ba3137c5cbc1716 Mon Sep 17 00:00:00 2001 From: prodigygirl Date: Sat, 22 Oct 2022 22:54:34 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BA=D0=B0=D1=80=D1=82=D1=8B=20SimpleMap?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/SimpleMap.java | 42 ++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/main/java/SimpleMap.java diff --git a/src/main/java/SimpleMap.java b/src/main/java/SimpleMap.java new file mode 100644 index 0000000..984b144 --- /dev/null +++ b/src/main/java/SimpleMap.java @@ -0,0 +1,42 @@ +import java.awt.*; + +public class SimpleMap extends AbstractMap{ + private final Color barrierColor = Color.BLACK; + private final Color roadColor = Color.GRAY; + @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++; + } + } + } + + @Override + protected void DrawRoadPart(Graphics2D g, int i, int j) { + g.setColor(roadColor); + g.fillRect(i * (int)size_x, j * (int)size_y, (int)size_x, (int)size_y); + } + + @Override + protected void DrawBarrierPart(Graphics2D g, int i, int j) { + g.setColor(barrierColor); + g.fillRect(i * (int)size_x, j * (int)size_y, (int)size_x, (int)size_y); + } +}