Looping border is now working!
This commit is contained in:
parent
fe2f80d27c
commit
8ddf555291
|
|
@ -87,16 +87,30 @@ public class Simulator extends Thread {
|
|||
|
||||
private int countAliveNeighbors(int x, int y) {
|
||||
int count = 0;
|
||||
for (int i = x - 1; i <= x + 1; i++) {
|
||||
for (int j = y - 1; j <= y + 1; j++) {
|
||||
if (i >= 0 && i < COL_NUM && j >= 0 && j < LINE_NUM && !(i == x && j == y)) {
|
||||
count += grid[i][j];
|
||||
for (int i = -1; i <= 1; i++) {
|
||||
for (int j = -1; j <= 1; j++) {
|
||||
if (i == 0 && j == 0) continue; // Skip the cell itself
|
||||
|
||||
int nx = x + i;
|
||||
int ny = y + j;
|
||||
|
||||
if (loopingBorder) { // looping border
|
||||
if (nx < 0) nx = COL_NUM - 1;
|
||||
else if (nx >= COL_NUM) nx = 0;
|
||||
if (ny < 0) ny = LINE_NUM - 1;
|
||||
else if (ny >= LINE_NUM) ny = 0;
|
||||
}
|
||||
else { // closed border
|
||||
if (nx < 0 || nx >= COL_NUM || ny < 0 || ny >= LINE_NUM) continue;
|
||||
}
|
||||
|
||||
count += grid[nx][ny];
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* method called at each step of the simulation
|
||||
* makes all the actions to go from one step to the other
|
||||
|
|
@ -322,7 +336,7 @@ public class Simulator extends Thread {
|
|||
}
|
||||
|
||||
public void toggleLoopingBorder() {
|
||||
loopingBorder =! loopingBorder;
|
||||
loopingBorder = !loopingBorder;
|
||||
}
|
||||
|
||||
public void setLoopDelay(int delay) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue