Добавление карты SimpleMap

This commit is contained in:
prodigygirl 2022-10-22 22:54:34 +04:00
parent e720b435c5
commit 25dad76145

View 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);
}
}