From 076dd4bef4bffc7c35c3f663c022e9e16f9039ef Mon Sep 17 00:00:00 2001 From: s23026062 <melis-damla.sahin@etu.univ-amu.fr> Date: Tue, 26 Nov 2024 13:43:16 +0100 Subject: [PATCH] =?UTF-8?q?impl=C3=A9menter=20la=20classe=20GameOfLifeStat?= =?UTF-8?q?e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/model/automata/GameOfLifeState.java | 37 +++++++++++++++---- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/src/main/java/model/automata/GameOfLifeState.java b/src/main/java/model/automata/GameOfLifeState.java index 12ee370..48f8156 100644 --- a/src/main/java/model/automata/GameOfLifeState.java +++ b/src/main/java/model/automata/GameOfLifeState.java @@ -14,20 +14,43 @@ public enum GameOfLifeState implements State<GameOfLifeState> { @Override public Color getColor() { - //TODO: à compléter - return Color.BLACK; + switch(this) { + case ALIVE: + return Color.RED; + case DEAD : + return Color.WHITE; + default : return Color.WHITE; + } } @Override public GameOfLifeState next() { - //TODO: à compléter - return null; + switch (this) { + case ALIVE: + return DEAD; + case DEAD: + return ALIVE; + default : return DEAD; + } } @Override public GameOfLifeState update(List<GameOfLifeState> neighbours) { - //TODO: à compléter - return null; + int count = State.count(ALIVE, neighbours); + switch (this) { + case DEAD: + if (count == 3) { + return ALIVE; + } + case ALIVE: + if (count == 3) { + return ALIVE; + } else if (count == 2) { + return ALIVE; + } + default: + return DEAD; + } } - } + -- GitLab