From 25f19abb4ee2aea5a52dea1e08b852152a9c0e5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matt=C3=A9o?= <mat.comti@gmail.com> Date: Mon, 12 Oct 2020 02:06:19 +0200 Subject: [PATCH] Everything done but unsure --- .idea/compiler.xml | 8 ++++++++ Grid.java | 19 +++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 .idea/compiler.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..0fe4a13 --- /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 ed6ef3b..4d63f94 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(); + } } } -- GitLab