grid and ra,dom grid done

This commit is contained in:
Paul EWING 2024-05-23 11:46:27 +02:00
parent 5e45df9159
commit 1172072971
2 changed files with 9 additions and 5 deletions

View File

@ -8,4 +8,4 @@ public class Main {
mjf.setVisible(true);
}
}
}

View File

@ -6,6 +6,7 @@ public class Grid {
private int height;
private int[][] grid;
private int rando;
private Random rand = new Random();
public Grid(int width, int height) {
this.width = width;
this.height = height;
@ -31,10 +32,13 @@ public class Grid {
public void fillRandom(float randomness) {
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
int rando = Random.nextInt(100);
int r= (int) randomness*100;
if(rando<r) {
grid[y][x] = 1;}
int rando = rand.nextInt(100);
int r = (int) (randomness * 100);
if (rando < r) {
grid[y][x] = 1;
} else {
grid[y][x] = 0;
}
}
}
}