diff --git a/AbstractMap.java b/AbstractMap.java index ce5d4b5..8c96b91 100644 --- a/AbstractMap.java +++ b/AbstractMap.java @@ -56,13 +56,14 @@ public abstract class AbstractMap { private boolean objectIntersects() { float[] location = _drawingObject.getCurrentPosition(); + Rectangle self = new Rectangle((int) location[0], (int) location[2], (int) location[1] - (int) location[0], (int) location[3] - (int) location[2]); for (int i = 0; i < _map.length; i++) { for (int j = 0; j < _map[i].length; j++) { if (_map[i][j] == _barrier) { - if (i * _size_x >= location[0] && (i + 1) * _size_x <= location[1] && j * _size_y >= location[2] && (j + 1) * _size_y <= location[3]) + if (self.intersects(new Rectangle(j * (int) _size_x, i * (int) _size_y, (int) _size_x, (int) _size_y))) { return true; } diff --git a/ForestMap.java b/ForestMap.java index 6a2eaf6..0936adb 100644 --- a/ForestMap.java +++ b/ForestMap.java @@ -9,14 +9,14 @@ public class ForestMap extends AbstractMap { 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)); + g.fillRect(j * (int) _size_x, i * (int) _size_y, (int) _size_x, (int) _size_y); } @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)); + g.fillRect(j * (int) _size_x, i * (int) _size_y, (int) _size_x, (int) _size_y); } @Override @@ -32,16 +32,16 @@ public class ForestMap extends AbstractMap { { int x = _random.nextInt(2, 49); int y = _random.nextInt(3, 50); - var points = new int[] { _map[x][y], _map[x][y - 1], _map[x][y - 2], _map[x - 1][y - 2], _map[x + 1][y - 2], _map[x][y - 3] }; + var points = new int[] { _map[y][x], _map[y - 1][x], _map[y - 2][x], _map[y - 2][x - 1], _map[y - 2][x + 1], _map[y - 3][x] }; var forComparison = new int[] { _freeRoad, _freeRoad, _freeRoad, _freeRoad, _freeRoad, _freeRoad }; if (Arrays.equals(points, forComparison)) { - _map[x][y] = _barrier; - _map[x][y - 1] = _barrier; - _map[x][y - 2] = _barrier; - _map[x - 1][y - 2] = _barrier; - _map[x + 1][y - 2] = _barrier; - _map[x][y - 3] = _barrier; + _map[y][x] = _barrier; + _map[y - 1][x] = _barrier; + _map[y - 2][x] = _barrier; + _map[y - 2][x - 1] = _barrier; + _map[y - 2][x + 1] = _barrier; + _map[y - 3][x] = _barrier; counter++; } } diff --git a/SimpleMap.java b/SimpleMap.java index 26db081..f9cb346 100644 --- a/SimpleMap.java +++ b/SimpleMap.java @@ -8,13 +8,13 @@ public class SimpleMap extends AbstractMap { @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)); + g.fillRect(j * (int) _size_x, i * (int) _size_y, (int) _size_x, (int) _size_y); } @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)); + g.fillRect(j * (int) _size_x, i * (int) _size_y, (int) _size_x, (int) _size_y); } @Override