PIbd-23_Minhasapov_R.H._Exc.../DumpMap.java

59 lines
1.8 KiB
Java

import java.awt.*;
public class DumpMap extends AbstractMap{
private final Color barrierColor = new Color(165,42,42);
private final Color roadColor = Color.LIGHT_GRAY;
@Override
protected void DrawBarrierPart(Graphics2D g, int j, int i)
{
g.setColor(barrierColor);
g.fillRect(i * (int)_size_x, j * (int)_size_y, (int)_size_x, (int)_size_y);
}
@Override
protected void DrawRoadPart(Graphics2D g, int j, int i)
{
g.setColor(roadColor);
g.fillRect(i * (int)_size_x, j * (int)_size_y, (int)_size_x, (int)_size_y);
}
@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 i = 0; i < _map.length; ++i)
{
for (int j = 0; j < _map[0].length; ++j)
{
_map[i][j] = _freeRoad;
}
}
while (counter < 20)
{
int x = _random.nextInt(0, 100);
int y = _random.nextInt(0, 100);
if (_map[y][x] == _freeRoad && x > 1 && x < 98 && y > 1 && y < 98)
{
_map[y][x] = _barrier;
_map[y][x + 1] = _barrier;
_map[y][x + 2] = _barrier;
_map[y][x - 1] = _barrier;
_map[y][x - 2] = _barrier;
_map[y + 1][x] = _barrier;
_map[y + 2][x] = _barrier;
_map[y - 1][x] = _barrier;
_map[y - 2][x] = _barrier;
_map[y + 1][x + 1] = _barrier;
_map[y - 1][x + 1] = _barrier;
_map[y + 1][x - 1] = _barrier;
_map[y - 1][x - 1] = _barrier;
counter++;
}
}
}
}