PIbd-21_Markov_D.P._Contain.../IslandsMap.java
2022-12-02 00:06:03 +04:00

58 lines
1.9 KiB
Java

import java.awt.*;
public class IslandsMap extends AbstractMap{
private final Color barrierColor = Color.YELLOW;
private final Color roadColor = Color.CYAN;
@Override
protected void DrawBarrierPart(Graphics g, int i, int j)
{
Graphics2D g2d = (Graphics2D) g;
g2d.setPaint(barrierColor);
g2d.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 g2d = (Graphics2D) g;
g2d.setPaint(roadColor);
g2d.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] = _water;
}
}
while (counter < 10)
{
int x = _random.nextInt(0, 100);
int y = _random.nextInt(0, 100);
if (_map[x][y] == _water && x < 98 && y < 99)
if (_map[x][y] == _water && x < 97 && y < 97)
{
_map[x + 1][y] = _barrier;
_map[x + 2][y] = _barrier;
_map[x][y + 1] = _barrier;
_map[x + 1][y + 1] = _barrier;
_map[x + 2][y + 1] = _barrier;
_map[x + 3][y + 1] = _barrier;
_map[x][y + 2] = _barrier;
_map[x + 1][y + 2] = _barrier;
_map[x + 2][y + 2] = _barrier;
_map[x + 3][y + 2] = _barrier;
_map[x + 1][y + 3] = _barrier;
_map[x + 2][y + 3] = _barrier;
counter++;
}
}
}
}