Borschevskaya A.A. Lab Work 2 Hard #2
42
src/main/java/SimpleMap.java
Normal file
42
src/main/java/SimpleMap.java
Normal file
@ -0,0 +1,42 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class SimpleMap extends AbstractMap{
|
||||
private final Color barrierColor = Color.BLACK;
|
||||
private final Color roadColor = Color.GRAY;
|
||||
@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(100);
|
||||
int y = random.nextInt(100);
|
||||
if (map[x][y] == _freeRoad)
|
||||
{
|
||||
map[x][y] = _barrier;
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void DrawRoadPart(Graphics2D g, int i, int j) {
|
||||
g.setColor(roadColor);
|
||||
g.fillRect(i * (int)size_x, j * (int)size_y, (int)size_x, (int)size_y);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void DrawBarrierPart(Graphics2D g, int i, int j) {
|
||||
g.setColor(barrierColor);
|
||||
g.fillRect(i * (int)size_x, j * (int)size_y, (int)size_x, (int)size_y);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user