Added class SimpleMap
This commit is contained in:
parent
ed422215f0
commit
0df20f4008
40
SimpleMap.java
Normal file
40
SimpleMap.java
Normal file
@ -0,0 +1,40 @@
|
||||
import java.awt.*;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class SimpleMap extends AbstractMap {
|
||||
private final Color barrierColor = Color.black;
|
||||
private final Color roadColor = Color.gray;
|
||||
|
||||
@Override
|
||||
protected void drawBarrierPart(Graphics2D g, int i, int j) {
|
||||
g.setColor(barrierColor);
|
||||
g.fillRect(i * (int) _size_x, j * (int) _size_y, i * ((int) _size_x + 1), j * ((int) _size_y + 1));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawRoadPart(Graphics2D g, int i, int j) {
|
||||
g.setColor(roadColor);
|
||||
g.fillRect(i * (int) _size_x, j * (int) _size_y, i * ((int) _size_x + 1), j * ((int) _size_y + 1));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateMap() {
|
||||
_map = new int[100][100];
|
||||
_size_x = (float)_width / _map[0].length;
|
||||
_size_y = (float)_height / _map.length;
|
||||
int counter = 0;
|
||||
for (int[] row : _map) {
|
||||
Arrays.fill(row, _freeRoad);
|
||||
}
|
||||
while (counter < 50)
|
||||
{
|
||||
int x = _random.nextInt(0, 100);
|
||||
int y = _random.nextInt(0, 100);
|
||||
if (_map[y][x] == _freeRoad)
|
||||
{
|
||||
_map[y][x] = _barrier;
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user