PIbd-22_Bondarenko_M.S._War.../SecondMap.java

59 lines
1.7 KiB
Java
Raw Normal View History

2022-11-29 22:18:43 +04:00
import java.awt.*;
public class SecondMap extends AbstractMap{
private Color barrierColor = Color.ORANGE;
private Color roadColor = Color.BLACK;
@Override
protected void DrawBarrierPart(Graphics g, int i, int j)
{
Graphics2D g2d = (Graphics2D) g;
g2d.setPaint(barrierColor);
g2d.fillRect((int)Math.floor(j * _size_x), (int)Math.floor(i * _size_y),(int)Math.ceil(_size_x), (int)Math.ceil(_size_y));
}
@Override
protected void DrawRoadPart(Graphics g, int i, int j)
{
Graphics2D g2d = (Graphics2D) g;
g2d.setPaint(roadColor);
g2d.fillRect((int)Math.floor(j * _size_x), (int)Math.floor(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 counter = 0;
for (int i = 0; i < _map.length; ++i)
{
for (int j = 0; j < _map[0].length; ++j)
{
_map[i][j] = _freeRoad;
}
}
for (int i = 0; i < _map.length; ++i)
{
_map[i][_map[0].length / 2] = _barrier;
_map[i][_map[0].length - 1] = _barrier;
}
for (int j = 0; j < _map[0].length; ++j)
{
_map[_map.length - 1][j] = _barrier;
}
while (counter < 45)
{
int x = _random.nextInt(0, 100);
int y = _random.nextInt(0, 100);
if (_map[x][y] == _freeRoad)
{
_map[x][y] = _barrier;
counter++;
}
}
}
}