diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000000000000000000000000000000000000..0fe4a139e13a572cd877e67f8e0639c163e5efc6 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="JavacSettings"> + <option name="ADDITIONAL_OPTIONS_OVERRIDE"> + <module name="TP3" options="--add-exports jdk.compiler/com.sun.tools.doclint=ALL-UNNAMED" /> + </option> + </component> +</project> \ No newline at end of file diff --git a/Grid.java b/Grid.java index ed6ef3bec5175a297d15d8a2be396fc04e119e75..4d63f94b3d9a07996821e314281a1c950f64db6c 100644 --- a/Grid.java +++ b/Grid.java @@ -139,10 +139,14 @@ public class Grid implements Iterable<Cell> { } private void goToNextState(boolean[][] nextState) { - Iterator<Cell> iterator = iterator(); - while (iterator.hasNext()) { - Cell cell = iterator.next(); - cell.isAlive() = nextState[][]; + for (Cell cell : this) { + for (int i = 0; i == numberOfRows - 1; i++) { + for (int j = 0; j == numberOfColumns - 1; j++) { + if (nextState[i][j]) { + cell.setAlive(); + } else cell.setDead(); + } + } } } @@ -150,6 +154,9 @@ public class Grid implements Iterable<Cell> { * Sets all {@link Cell}s in this {@code Grid} as dead. */ void clear() { + for (Cell cell : this) { + cell.setDead(); + } } /** @@ -160,6 +167,10 @@ public class Grid implements Iterable<Cell> { */ void randomGeneration(Random random) { + for (Cell cell : this) { + if (random.nextBoolean()) {cell.setAlive();} + else cell.setDead(); + } } }