Neues GUI und icons

This commit is contained in:
Noah
2021-09-28 22:29:35 +02:00
parent c3e19db3d3
commit 33e76f12d0
+67 -2
View File
@@ -2,16 +2,20 @@ package game;
import gui.GUI; import gui.GUI;
import java.util.concurrent.ThreadLocalRandom;
public class Control { public class Control {
private GUI gui; private GUI gui;
private int xSize, ySize, cellCount; private int xSize, ySize, cellCount, gen = 0;
private boolean[][] cells;
private boolean[][] newcells;
public Control(){ public Control(){
gui = new GUI(this); gui = new GUI(this);
gui.buildControlWindow(); gui.buildControlWindow();
} }
@@ -21,10 +25,71 @@ public class Control {
this.ySize = ySize; this.ySize = ySize;
this.cellCount = cellCount; this.cellCount = cellCount;
cells = new boolean[this.xSize][this.ySize];
newcells = new boolean[this.xSize][this.ySize];
gui.buildGameWindow(); gui.buildGameWindow();
} }
private void nextGen(){
gen ++;
System.out.println("Generation:" + gen);
for (int x = 0; x < xSize; x++){
for (int y = 0; y < ySize; y++) {
int n = aliveNeigbours(x, y);
if (n == 3 && !cells[x][y]){
newcells[x][y] = true;
}
if (n < 2){
newcells[x][y] = false;
}
if (n == 2 || n == 3){
}
if (n > 3){
newcells[x][y] = false;
}
}
}
for (int x = 0; x < xSize; x++) {
for (int y = 0; y < ySize; y++) {
cells[x][y] = newcells[x][y];
}
}
}
private int aliveNeigbours(int x, int y){
int count = 0;
int[] xoff = {1, 1, 0, -1, -1, -1, 0, 1};
int[] yoff = {0, 1, 1, 1, 0, -1, -1, -1};
for (int i = 0; i < 8; i++){
try {
if (cells[x + xoff[i]][y + yoff[i]]){
count ++;
}
} catch (Exception e) {
}
}
return count;
}
private int rand(int min, int max){
return ThreadLocalRandom.current().nextInt(min, max);
}
} }