2022-11-03 23:34:20 +04:00
|
|
|
import java.awt.*;
|
|
|
|
|
2022-11-05 13:06:59 +04:00
|
|
|
public class SimpleMap extends AbstractMap
|
|
|
|
{
|
2022-11-03 23:34:20 +04:00
|
|
|
//цвет закрытого участка
|
|
|
|
private final Color barriedColor = Color.black;
|
|
|
|
|
|
|
|
//цвет открытого участка
|
|
|
|
private final Color roadColor = Color.gray;
|
|
|
|
|
|
|
|
@Override
|
2022-11-05 13:06:59 +04:00
|
|
|
protected void GenerateMap()
|
|
|
|
{
|
2022-11-03 23:34:20 +04:00
|
|
|
_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 < 50)
|
|
|
|
{
|
|
|
|
int x = _random.nextInt(0, 100);
|
|
|
|
int y = _random.nextInt(0, 100);
|
|
|
|
|
|
|
|
if (_map[x][y] == _freeRoad)
|
|
|
|
{
|
|
|
|
_map[x][y] = _barrier;
|
|
|
|
counter++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2022-11-05 13:06:59 +04:00
|
|
|
protected void DrawRoadPart(Graphics g, int i, int j)
|
|
|
|
{
|
2022-11-03 23:34:20 +04:00
|
|
|
Graphics2D g2d = (Graphics2D)g;
|
|
|
|
g2d.setPaint(roadColor);
|
2022-11-05 01:24:27 +04:00
|
|
|
g2d.fillRect((int)(i * _size_x), (int)(j * _size_y), (int)(i * (_size_x + 1)), (int)(j *(_size_y + 1)));
|
2022-11-03 23:34:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2022-11-05 13:06:59 +04:00
|
|
|
protected void DrawBarrierPart(Graphics g, int i, int j)
|
|
|
|
{
|
2022-11-03 23:34:20 +04:00
|
|
|
Graphics2D g2d = (Graphics2D)g;
|
|
|
|
g2d.setPaint(barriedColor);
|
2022-11-05 01:24:27 +04:00
|
|
|
g2d.fillRect((int)(i * _size_x), (int)(j * _size_y), (int)(i * (_size_x + 1)), (int)(j *(_size_y + 1)));
|
2022-11-03 23:34:20 +04:00
|
|
|
}
|
|
|
|
}
|