54 lines
1.5 KiB
Java
54 lines
1.5 KiB
Java
import java.awt.*;
|
|
|
|
public class LineMap extends AbstractMap{
|
|
@Override
|
|
protected void DrawBarrierPart(Graphics g, int i, int j)
|
|
{
|
|
Graphics2D g2 = (Graphics2D) g;
|
|
g2.setColor(Color.gray);
|
|
g2.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)
|
|
{
|
|
Graphics2D g2 = (Graphics2D) g;
|
|
g2.setColor(Color.BLUE);
|
|
g2.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[i].length; ++j)
|
|
{
|
|
_map[i][j] = _freeRoad;
|
|
}
|
|
}
|
|
boolean flag = true;
|
|
while (counter < 20)
|
|
{
|
|
int lineX = _random.nextInt(11, 89);
|
|
int lineY = _random.nextInt(11, 89);
|
|
|
|
if (flag)
|
|
{
|
|
for (int i = lineY; i <= lineY + 10; i++)
|
|
_map[lineX][i] = _barrier;
|
|
flag = false;
|
|
}
|
|
else
|
|
{
|
|
for (int i = lineX; i <= lineX + 10; i++)
|
|
_map[i][lineY] = _barrier;
|
|
flag = true;
|
|
}
|
|
counter++;
|
|
}
|
|
}
|
|
}
|