MapGenerator #34

Merged
tonitch merged 5 commits from MapGenerator into master 2023-05-01 18:38:53 +02:00
3 changed files with 51 additions and 2 deletions
Showing only changes of commit 5dceec0f79 - Show all commits

View File

@ -1,9 +1,13 @@
package school_project;
import school_project.Utils.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;
public class MapGenerator {
private static Random rand = new Random();
private static final Random rand = new Random();
public enum Difficulty {
Easy,
Medium,
@ -24,6 +28,7 @@ public class MapGenerator {
default -> map_size = new Vec2();
}
// Cut edges
boolean[][] map_shape = new boolean[map_size.x][map_size.y];
for (boolean[] b : map_shape) {
Arrays.fill(b, true);
@ -36,6 +41,11 @@ public class MapGenerator {
map_shape[i][j] = rand.nextBoolean();
}
}
return new Map(map_shape);
Map ret = new Map(map_shape);
boolean[][] piece_layout = Array.MatrixCopyOf(map_shape);
//generate pieces
return ret;
}
}

View File

@ -0,0 +1,13 @@
package school_project.Utils;
import java.util.Arrays;
public class Array{
public static boolean[][] MatrixCopyOf(boolean[][] o){
boolean[][] ret = new boolean[o.length][];
for (int i = 0; i < o.length; i++){
ret[i] = Arrays.copyOf(o[i], o[i].length);
}
return ret;
}
}

View File

@ -0,0 +1,26 @@
package school_project.Utils;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class ArrayTest {
@Test
void matrixCopyOf() {
boolean[][] a = new boolean[][] {
{true, false, true},
{false, false, false},
{true, false, true},
};
boolean[][] b = new boolean[][] {
{true, false, true},
{false, false, false},
{true, false, true},
};
boolean[][] c = Array.MatrixCopyOf(a);
assertArrayEquals(a, c);
a[1][1] = true;
assertArrayEquals(b, c);
}
}