Pibd-23_Zhelovanov_D.Y._Bat.../SeaMap.java

45 lines
1.3 KiB
Java
Raw Normal View History

2022-12-06 17:23:28 +04:00
import java.awt.*;
public class SeaMap extends AbstractMap {
@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 < 10)
{
int x = _random.nextInt(1, 99);
int y = _random.nextInt(1, 100);
if (_map[x][y] == _freeRoad)
{
_map[x][y] = _barrier;
_map[x + 1][y] = _barrier;
counter++;
}
}
}
@Override
protected void DrawRoadPart(Graphics g, int i, int j) {
g.setColor(Color.BLUE);
g.fillRect((int) (i * _size_x), (int) (j * _size_y), (int)(i * (_size_x + 1)), (int)(j * (_size_y + 1)));
}
@Override
protected void DrawBarrierPart(Graphics g, int i, int j) {
g.setColor(Color.WHITE);
g.fillPolygon(new int[]{i * (int) _size_x, i * (int) _size_x + 18, i * (int) _size_x - 18},new int[]{ j * (int) _size_y, j * (int) _size_y + 20,
j * (int) _size_y + 20}, 3);
}
}