58 lines
1.5 KiB
Java
58 lines
1.5 KiB
Java
import java.awt.*;
|
|
|
|
public class ThirdMap extends AbstractMap {
|
|
|
|
Color roadColor = Color.LIGHT_GRAY;
|
|
Color barrierColor = Color.GRAY;
|
|
@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 < 60)
|
|
{
|
|
int x = _random.nextInt(0, 20);
|
|
int y = _random.nextInt(40, 60);
|
|
if (_map[x][y] == _freeRoad)
|
|
{
|
|
_map[x][y] = _barrier;
|
|
counter++;
|
|
}
|
|
|
|
x = _random.nextInt(80, 100);
|
|
y = _random.nextInt(0, 20);
|
|
if (_map[x][y] == _freeRoad)
|
|
{
|
|
_map[x][y] = _barrier;
|
|
counter++;
|
|
}
|
|
|
|
x = _random.nextInt(40, 60);
|
|
y = _random.nextInt(50, 80);
|
|
if (_map[x][y] == _freeRoad)
|
|
{
|
|
_map[x][y] = _barrier;
|
|
counter++;
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override
|
|
protected Color DrawRoadPart() {
|
|
return roadColor;
|
|
}
|
|
|
|
@Override
|
|
protected void DrawBarrierPart(Graphics g, int i, int j) {
|
|
g.setColor(barrierColor);
|
|
g.fillRect( (int)(i * _size_x), (int)(j * _size_y),(int) _size_x,(int) _size_y);
|
|
}
|
|
} |