import java.awt.*;
import java.util.Arrays;

public class ForestMap extends AbstractMap {
    private final Color barrierColor = Color.green;
    private final Color roadColor = new Color(165, 42, 42, 255);

    @Override
    protected void drawBarrierPart(Graphics2D g, int i, int j)
    {
        g.setColor(barrierColor);
        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(j * (int) _size_x, i * (int) _size_y, (int) _size_x, (int) _size_y);
    }

    @Override
    protected void generateMap() {
        _map = new int[50][50];
        _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 < 20)
        {
            int x = _random.nextInt(2, 49);
            int y = _random.nextInt(3, 50);
            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[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++;
            }
        }
    }
}