56 lines
1.6 KiB
Java
56 lines
1.6 KiB
Java
import java.awt.*;
|
|
import java.util.Random;
|
|
|
|
public class StarWarsMap extends AbstractMap{
|
|
Random rnd = new Random();
|
|
|
|
//цвет закрытого участка
|
|
Color barriedColor;
|
|
|
|
//цвет открытого участка
|
|
private final Color roadColor = new Color(0, 0, 139);
|
|
|
|
@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 < 50)
|
|
{
|
|
int x = _random.nextInt(0, 100);
|
|
int y = _random.nextInt(0, 100);
|
|
|
|
if (_map[x][y] == _freeRoad)
|
|
{
|
|
_map[x][y] = _barrier;
|
|
counter++;
|
|
}
|
|
}
|
|
}
|
|
|
|
@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 DrawBarrierPart(Graphics g, int i, int j) {
|
|
Graphics2D g2d = (Graphics2D)g;
|
|
barriedColor = new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));
|
|
g2d.setPaint(barriedColor);
|
|
g2d.fillRect((int)(i * _size_x), (int)(j * _size_y), (int)(i * (_size_x + 1)), (int)(j *(_size_y + 1)));
|
|
}
|
|
}
|