Borschevskaya A.A. Lab Work 2 Hard #2
65
src/main/java/MyMapLabyrinth.java
Normal file
65
src/main/java/MyMapLabyrinth.java
Normal file
@ -0,0 +1,65 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class MyMapLabyrinth extends AbstractMap{
|
||||
private final Color barrierColor = Color.BLUE;
|
||||
private final Color roadColor = Color.BLACK;
|
||||
@Override
|
||||
protected void GenerateMap() {
|
||||
map = new int[50][50];
|
||||
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 < 20)
|
||||
{
|
||||
int x = random.nextInt(0, 50);
|
||||
int y = random.nextInt(0, 50);
|
||||
int number = random.nextInt(1, 16);
|
||||
if (counter < 5) {
|
||||
if (number + x > map.length)
|
||||
{
|
||||
number = map.length - x - 1;
|
||||
}
|
||||
for (int i = x; i < x + number; ++i)
|
||||
{
|
||||
map[i][y] = _barrier;
|
||||
}
|
||||
} else
|
||||
{
|
||||
if (number + y > map[0].length)
|
||||
{
|
||||
number = map[0].length - y - 1;
|
||||
}
|
||||
for (int i = y; i < y + number; ++i)
|
||||
{
|
||||
map[x][i] = _barrier;
|
||||
}
|
||||
}
|
||||
counter++;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void DrawRoadPart(Graphics2D g, int i, int j) {
|
||||
g.setColor(roadColor);
|
||||
int new_size_x = Math.round(size_x);
|
||||
int new_size_y = Math.round(size_y);
|
||||
g.fillRect(i * new_size_x, j * new_size_y, new_size_x, new_size_y);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void DrawBarrierPart(Graphics2D g, int i, int j) {
|
||||
g.setColor(barrierColor);
|
||||
int new_size_x = Math.round(size_x);
|
||||
int new_size_y = Math.round(size_y);
|
||||
g.fillRect(i * new_size_x, j * new_size_y, new_size_x, new_size_y);
|
||||
}
|
||||
}
|
46
src/main/java/MyMapWooden.java
Normal file
46
src/main/java/MyMapWooden.java
Normal file
@ -0,0 +1,46 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class MyMapWooden extends AbstractMap{
|
||||
private final Color barrierColor = new Color(45, 77, 44);
|
||||
private final Color roadColor = new Color(105, 70, 35);
|
||||
@Override
|
||||
protected void GenerateMap() {
|
||||
map = new int[10][10];
|
||||
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(10);
|
||||
int y = random.nextInt(10);
|
||||
if (map[x][y] == _freeRoad)
|
||||
{
|
||||
map[x][y] = _barrier;
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void DrawRoadPart(Graphics2D g, int i, int j) {
|
||||
g.setColor(roadColor);
|
||||
int new_size_x = Math.round(size_x);
|
||||
int new_size_y = Math.round(size_y);
|
||||
g.fillRect(i * new_size_x, j * new_size_y, new_size_x, new_size_y);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void DrawBarrierPart(Graphics2D g, int i, int j) {
|
||||
g.setColor(barrierColor);
|
||||
int new_size_x = Math.round(size_x);
|
||||
int new_size_y = Math.round(size_y);
|
||||
g.fillRect(i * new_size_x, j * new_size_y, new_size_x, new_size_y);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user