From d05f4211f1e20a0a12684dd947646ab21e44b4cd Mon Sep 17 00:00:00 2001 From: "balthazar.squinabol" Date: Wed, 3 Apr 2024 17:38:04 +0200 Subject: [PATCH 1/5] togglePause --- src/backend/Simulator.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/backend/Simulator.java b/src/backend/Simulator.java index c5c839e..9cb9b44 100644 --- a/src/backend/Simulator.java +++ b/src/backend/Simulator.java @@ -140,7 +140,8 @@ public class Simulator extends Thread { * method called when clicking pause button */ public void togglePause() { - // TODO : actually toggle the corresponding flag + // TODO-COMPLETE : actually toggle the corresponding flag + pauseFlag = !pauseFlag; } /** From b27ef8ffe0dc2c5208185be606be88557d309e4e Mon Sep 17 00:00:00 2001 From: "balthazar.squinabol" Date: Wed, 3 Apr 2024 17:42:11 +0200 Subject: [PATCH 2/5] clickCell --- src/backend/Simulator.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/backend/Simulator.java b/src/backend/Simulator.java index 9cb9b44..3698e30 100644 --- a/src/backend/Simulator.java +++ b/src/backend/Simulator.java @@ -148,7 +148,17 @@ public class Simulator extends Thread { * method called when clicking on a cell in the interface */ public void clickCell(int x, int y) { - //TODO : complete method + int currentCellValue = getCell(x, y); + int newCellValue; + if (currentCellValue == 0) { + System.out.println("Cell :" + x + "," + y + " is now alive"); + newCellValue = 1; // If the cell is dead, make it alive + } else { + System.out.println("Cell :" + x + "," + y + " is now dead"); + newCellValue = 0; // If the cell is alive, make it dead + } + + setCell(x, y, newCellValue); } /** From 3c05da825fc559ee842b1404eb3e19d599ae33f4 Mon Sep 17 00:00:00 2001 From: "balthazar.squinabol" Date: Wed, 3 Apr 2024 18:12:42 +0200 Subject: [PATCH 3/5] clickActionFlag add to clickCell add setLoopDelay add toggleClickAction --- src/backend/Simulator.java | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/backend/Simulator.java b/src/backend/Simulator.java index 3698e30..5172df5 100644 --- a/src/backend/Simulator.java +++ b/src/backend/Simulator.java @@ -148,17 +148,21 @@ public class Simulator extends Thread { * method called when clicking on a cell in the interface */ public void clickCell(int x, int y) { - int currentCellValue = getCell(x, y); - int newCellValue; - if (currentCellValue == 0) { - System.out.println("Cell :" + x + "," + y + " is now alive"); - newCellValue = 1; // If the cell is dead, make it alive + if (clickActionFlag) { + int currentCellValue = getCell(x, y); + int newCellValue; + if (currentCellValue == 0) { + System.out.println("Cell :" + x + "," + y + " is now alive"); + newCellValue = 1; // If the cell is dead, make it alive + } else { + System.out.println("Cell :" + x + "," + y + " is now dead"); + newCellValue = 0; // If the cell is alive, make it dead + } + + setCell(x, y, newCellValue); } else { - System.out.println("Cell :" + x + "," + y + " is now dead"); - newCellValue = 0; // If the cell is alive, make it dead + return; } - - setCell(x, y, newCellValue); } /** @@ -277,11 +281,13 @@ public class Simulator extends Thread { } public void setLoopDelay(int delay) { - //TODO : complete method + //TODO-COMPLETE : complete method + loopDelay = delay; } public void toggleClickAction() { - //TODO : complete method + //TODO-COMPLETE : complete method + clickActionFlag = !clickActionFlag; } /** From 4f2cb0964084978bd0f9f33c985ffa09f2643ba2 Mon Sep 17 00:00:00 2001 From: "balthazar.squinabol" Date: Wed, 3 Apr 2024 18:19:28 +0200 Subject: [PATCH 4/5] add logs --- src/backend/Simulator.java | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/backend/Simulator.java b/src/backend/Simulator.java index 5172df5..4075a0c 100644 --- a/src/backend/Simulator.java +++ b/src/backend/Simulator.java @@ -28,6 +28,7 @@ public class Simulator extends Thread { //TODO : add missing attribute(s) private int width; private int height; + private boolean enableLogs; public Simulator(MyInterface mjfParam) { mjf = mjfParam; @@ -44,6 +45,7 @@ public class Simulator extends Thread { //might want to changes those values later this.width=100; this.height=100; + enableLogs = true; //Default rule : Survive always, birth never @@ -142,6 +144,13 @@ public class Simulator extends Thread { public void togglePause() { // TODO-COMPLETE : actually toggle the corresponding flag pauseFlag = !pauseFlag; + if (enableLogs) { + if (pauseFlag) { + System.out.println("togglePause called, Simulation paused"); + } else { + System.out.println("togglePause called, Simulation unpaused"); + } + } } /** @@ -152,10 +161,14 @@ public class Simulator extends Thread { int currentCellValue = getCell(x, y); int newCellValue; if (currentCellValue == 0) { - System.out.println("Cell :" + x + "," + y + " is now alive"); + if (enableLogs) { + System.out.println("clickCell Called, cell :" + x + "," + y + " is now alive"); + } newCellValue = 1; // If the cell is dead, make it alive } else { - System.out.println("Cell :" + x + "," + y + " is now dead"); + if (enableLogs) { + System.out.println("clickCell Called, cell :" + x + "," + y + " is now dead"); + } newCellValue = 0; // If the cell is alive, make it dead } @@ -283,11 +296,21 @@ public class Simulator extends Thread { public void setLoopDelay(int delay) { //TODO-COMPLETE : complete method loopDelay = delay; + if (enableLogs) { + System.out.println("Loop delay set to " + delay); + } } public void toggleClickAction() { //TODO-COMPLETE : complete method clickActionFlag = !clickActionFlag; + if (enableLogs) { + if (clickActionFlag) { + System.out.println("toggleClickAction called, set clickActionFlag to true"); + } else { + System.out.println("toggleClickAction called, set clickActionFlag to false"); + } + } } /** From 40a88fe15e2c646b161ac151f95f8bab29193e24 Mon Sep 17 00:00:00 2001 From: "balthazar.squinabol" Date: Wed, 3 Apr 2024 18:33:01 +0200 Subject: [PATCH 5/5] nothing special --- src/backend/Simulator.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/backend/Simulator.java b/src/backend/Simulator.java index 4075a0c..14ccf9f 100644 --- a/src/backend/Simulator.java +++ b/src/backend/Simulator.java @@ -45,7 +45,7 @@ public class Simulator extends Thread { //might want to changes those values later this.width=100; this.height=100; - enableLogs = true; + enableLogs = true; // for debugging purposes //Default rule : Survive always, birth never @@ -193,8 +193,8 @@ public class Simulator extends Thread { * @return list of Animals in simulated world */ public ArrayList getAnimals(){ - return agents; - } + return agents; +} /** * selects Animals in a circular area of simulated world * @param x center @@ -221,6 +221,9 @@ public class Simulator extends Thread { */ public void setCell(int x, int y, int val) { //TODO : complete method + //j'ai ajouté une base, mais manque la partie qui modifie la valeur de la cellule + int currentCellValue = getCell(x, y); + // set cell value to !currentCellValue } /**