This commit is contained in:
sebas 2024-05-23 11:34:25 +02:00
parent f3c22f0916
commit 5e45df9159
2 changed files with 14 additions and 1 deletions

View File

@ -1,10 +1,11 @@
package backend;
import java.util.Random;
public class Grid {
private int width;
private int height;
private int[][] grid;
private int rando;
public Grid(int width, int height) {
this.width = width;
this.height = height;
@ -26,4 +27,15 @@ public class Grid {
throw new IndexOutOfBoundsException("Grid position out of range");
}
}
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;}
}
}
}
}

View File

@ -256,6 +256,7 @@ public class Simulator extends Thread {
* maybe just make a constructor in there
* and use it here
*/
maingrid.fillRandom(chanceOfLife);
}
public boolean isLoopingBorder() {