Added & fixed SpikeMap

This commit is contained in:
Данила Мочалов 2022-10-08 20:43:57 +04:00
parent 8e0a97dd2b
commit aba03789ef
2 changed files with 54 additions and 0 deletions

View File

@ -44,6 +44,7 @@ public class FormMap extends JComponent {
_abstractMap = new SimpleMap(); _abstractMap = new SimpleMap();
break; break;
case ("Spike Map"): case ("Spike Map"):
_abstractMap = new SpikeMap();
break; break;
case ("Rail Map"): case ("Rail Map"):
break; break;

53
SpikeMap.java Normal file
View File

@ -0,0 +1,53 @@
import java.awt.*;
public class SpikeMap extends AbstractMap{
/// Цвет участка закрытого
private final Color barrierColor = Color.BLACK;
/// Цвет участка открытого
private final Color roadColor = Color.GREEN;
@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 < 15)
{
int x = _random.nextInt(95) + 1;
int y = _random.nextInt(95) + 1;
if (_map[x][y] == _freeRoad)
{
_map[x][y] = _barrier;
if (_map[x + 1][y] == _freeRoad) _map[x + 1][y] = _barrier;
if (_map[x - 1][y] == _freeRoad) _map[x - 1][y] = _barrier;
if (_map[x][y + 1] == _freeRoad) _map[x][y + 1] = _barrier;
if (_map[x][y - 1] == _freeRoad) _map[x][y - 1] = _barrier;
counter++;
}
}
}
}