2022-12-04 12:42:37 +03:00

59 lines
1.5 KiB
Java

import java.awt.*;
import java.util.Random;
public class MyMap extends AbstractMap
{
private Color barrierColor = Color.BLACK;
private Color roadColor = new Color(235,252,255);
Random rnd = new Random();
@Override
protected void DrawBarrierPart(Graphics2D g, int i, int j)
{
g.setPaint(barrierColor);
g.fillRect((int)(j * _size_x), (int)(i * _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)(j * _size_x), (int)(i * _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 sizeHole = 70;
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 < 3)
{
Random rand = new Random();
int iWall = rnd.nextInt(0, 100);
int jWall = rnd.nextInt(0, 100);
if (iWall > _map.length - sizeHole)
continue;
for (int i = 0; i < _map.length; i++)
{
if (i < iWall || i > iWall + sizeHole)
_map[jWall][i] = _barrier;
}
counter++;
}
}
}