45 lines
1.3 KiB
Java
45 lines
1.3 KiB
Java
import java.awt.*;
|
|
|
|
public class MyMap extends AbstractMap{
|
|
private Color barrierColor = Color.WHITE;
|
|
private Color roadColor = Color.CYAN;
|
|
|
|
@Override
|
|
protected void DrawBarrierPart(Graphics2D g, int i, int j)
|
|
{
|
|
g.setPaint(barrierColor);
|
|
g.fillRect((int)Math.floor(i * _size_x), (int)Math.floor(j * _size_y), (int)Math.ceil(_size_x), (int)Math.ceil(_size_y));
|
|
}
|
|
@Override
|
|
protected void DrawRoadPart(Graphics2D g, int i, int j)
|
|
{
|
|
g.setPaint(roadColor);
|
|
g.fillRect((int)Math.floor(i * _size_x), (int)Math.floor(j * _size_y), (int)Math.ceil(_size_x), (int)Math.ceil(_size_y));
|
|
}
|
|
@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 < 25)
|
|
{
|
|
int x = _random.nextInt(0, 100);
|
|
int y = _random.nextInt(0, 100);
|
|
if (_map[x][y] == _freeRoad)
|
|
{
|
|
_map[x][y] = _barrier;
|
|
counter++;
|
|
}
|
|
}
|
|
}
|
|
}
|