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

41 lines
1.2 KiB
Java
Raw Permalink Normal View History

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(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[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, (int)_map[0].length);
int y = _random.nextInt(0, (int)_map.length);
if (_map[y][x] == _freeRoad)
{
_map[y][x] = _barrier;
counter++;
}
}
}
}