59 lines
1.6 KiB
Java
59 lines
1.6 KiB
Java
import java.awt.*;
|
|
|
|
public class RailMap extends AbstractMap{
|
|
/// Цвет участка закрытого
|
|
private final Color barrierColor = Color.BLACK;
|
|
/// Цвет участка открытого
|
|
private final Color roadColor = Color.PINK;
|
|
|
|
@Override
|
|
protected void DrawBarrierPart(Graphics g, int i, int j)
|
|
{
|
|
g.setColor(barrierColor);
|
|
g.fillRect( (int)(i * _size_x), (int)(j * _size_y), (int)(i * (_size_x +
|
|
1)), (int)(j * (_size_y + 1)));
|
|
}
|
|
|
|
@Override
|
|
protected void DrawRoadPart(Graphics g, int i, int j)
|
|
{
|
|
g.setColor(roadColor);
|
|
g.fillRect( (int)(i * _size_x), (int)(j * _size_y), (int)(i * (_size_x +
|
|
1)),(int)( j * (_size_y + 1)));
|
|
}
|
|
@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 < 1)
|
|
{
|
|
int y = _random.nextInt(85);
|
|
|
|
for(int x = 0; x < 99; x++)
|
|
{
|
|
_map[x][y] = _barrier;
|
|
_map[x][y + 5] = _barrier;
|
|
|
|
if (x % 5 == 0)
|
|
{
|
|
_map[x][y + 1] = _barrier;
|
|
_map[x][y + 2] = _barrier;
|
|
_map[x][y + 3] = _barrier;
|
|
_map[x][y + 4] = _barrier;
|
|
}
|
|
}
|
|
counter += 1;
|
|
}
|
|
}
|
|
}
|