From 0a534715b8ba4946aa0a03d2ad3514fcfaba07a0 Mon Sep 17 00:00:00 2001 From: Balthazar SQUINABOL Date: Wed, 10 Apr 2024 15:41:45 +0200 Subject: [PATCH 01/13] Actualiser src/windowInterface/MyInterface.java --- src/windowInterface/MyInterface.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/windowInterface/MyInterface.java b/src/windowInterface/MyInterface.java index 67ae441..f506362 100644 --- a/src/windowInterface/MyInterface.java +++ b/src/windowInterface/MyInterface.java @@ -165,6 +165,11 @@ public class MyInterface extends JFrame { randSlider.setMinimum(0); randSlider.setMaximum(100); randSlider.setPreferredSize(new Dimension(30,200)); + randSlider.addChangeListener(new ChangeListener() { + public void stateChanged(ChangeEvent arg0) { + changeDansity(); + } + }); panelRight.add(randSlider); @@ -254,6 +259,15 @@ public class MyInterface extends JFrame { } } + public void changeDansity() { + if(mySimu != null) { + double density = ((double)randSlider.getValue())/((double)randSlider.getMaximum()); + mySimu.setDansity(density); + } else { + randSlider.setValue(50); + } + } + public void clicLoadFileButton() { Simulator loadedSim = new Simulator(this); String fileName=SelectFile(); From 523bf7d0cb8b318574ebec0077f1bcbbb6e73ceb Mon Sep 17 00:00:00 2001 From: Balthazar SQUINABOL Date: Wed, 10 Apr 2024 15:42:12 +0200 Subject: [PATCH 02/13] Actualiser src/backend/Simulator.java --- src/backend/Simulator.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/backend/Simulator.java b/src/backend/Simulator.java index 8826654..41970c4 100644 --- a/src/backend/Simulator.java +++ b/src/backend/Simulator.java @@ -26,6 +26,7 @@ public class Simulator extends Thread { private int loopDelay = 150; //TODO : add missing attribute(s) + private double randomDansitySlider = 0.5; private int width; private int height; private boolean enableLogs; @@ -316,6 +317,13 @@ public class Simulator extends Thread { System.out.println("Loop delay set to " + delay); } } + + public void setDansity(double density) { + randomDansitySlider = density; + if (enableLogs) { + System.out.println("Density set to " + density); + } + } public void toggleClickAction() { //TODO-COMPLETE : complete method From 343c71dc317aee3d5caa32ac9b6c57dd3ac996bc Mon Sep 17 00:00:00 2001 From: "guillaume.bonabau" Date: Wed, 10 Apr 2024 15:46:01 +0200 Subject: [PATCH 03/13] starting step --- src/backend/Simulator.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/backend/Simulator.java b/src/backend/Simulator.java index 8826654..695a326 100644 --- a/src/backend/Simulator.java +++ b/src/backend/Simulator.java @@ -29,6 +29,7 @@ public class Simulator extends Thread { private int width; private int height; private boolean enableLogs; + private Table table; public Simulator(MyInterface mjfParam) { mjf = mjfParam; @@ -46,6 +47,7 @@ public class Simulator extends Thread { this.width=COL_NUM; this.height=LINE_NUM; enableLogs = true; // for debugging purposes + table = new Table(height, width); //Default rule : Survive always, birth never @@ -110,8 +112,16 @@ public class Simulator extends Thread { } } //then evolution of the field - // TODO : apply game rule to all cells of the field - + // TODO-INPROGRESS : apply game rule to all cells of the field + Table tempTable = new Table(this.height, this.width); + for(int x=0; x Date: Wed, 10 Apr 2024 15:46:01 +0200 Subject: [PATCH 04/13] starting step --- src/backend/Simulator.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/backend/Simulator.java b/src/backend/Simulator.java index 8826654..695a326 100644 --- a/src/backend/Simulator.java +++ b/src/backend/Simulator.java @@ -29,6 +29,7 @@ public class Simulator extends Thread { private int width; private int height; private boolean enableLogs; + private Table table; public Simulator(MyInterface mjfParam) { mjf = mjfParam; @@ -46,6 +47,7 @@ public class Simulator extends Thread { this.width=COL_NUM; this.height=LINE_NUM; enableLogs = true; // for debugging purposes + table = new Table(height, width); //Default rule : Survive always, birth never @@ -110,8 +112,16 @@ public class Simulator extends Thread { } } //then evolution of the field - // TODO : apply game rule to all cells of the field - + // TODO-INPROGRESS : apply game rule to all cells of the field + Table tempTable = new Table(this.height, this.width); + for(int x=0; x Date: Wed, 10 Apr 2024 16:04:09 +0200 Subject: [PATCH 05/13] worked on step --- src/backend/Cell.java | 4 ++-- src/backend/Simulator.java | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/backend/Cell.java b/src/backend/Cell.java index 0c0ec6e..cfd5a9e 100644 --- a/src/backend/Cell.java +++ b/src/backend/Cell.java @@ -15,10 +15,10 @@ public class Cell { public int getDensity() { return density; } - public int setValue(int value) { + public void setValue(int value) { this.value = value; } - public int setDensity(int density){ + public void setDensity(int density){ this.density = density; } } diff --git a/src/backend/Simulator.java b/src/backend/Simulator.java index 695a326..65a7088 100644 --- a/src/backend/Simulator.java +++ b/src/backend/Simulator.java @@ -116,11 +116,22 @@ public class Simulator extends Thread { Table tempTable = new Table(this.height, this.width); for(int x=0; x3) { + tempTable.getCell(x,y).setValue(0); + } + } else { + if(table.countNear(x,y)==3) { + tempTable.getCell(x,y).setValue(1); + } } + + } } + this.table = tempTable; /* you should distribute this action in methods/classes * don't write everything here ! From 5367724a2b217b504ced6ed2c576239af7260b2f Mon Sep 17 00:00:00 2001 From: "balthazar.squinabol" Date: Wed, 10 Apr 2024 16:08:43 +0200 Subject: [PATCH 06/13] YES --- src/backend/Simulator.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/backend/Simulator.java b/src/backend/Simulator.java index 41970c4..f8e45bd 100644 --- a/src/backend/Simulator.java +++ b/src/backend/Simulator.java @@ -307,6 +307,14 @@ public class Simulator extends Thread { public void toggleLoopingBorder() { //TODO : complete method + loopingBorder = !loopingBorder; + if (enableLogs) { + if (loopingBorder) { + System.out.println("toggleLoopingBorder called, set loopingBorder to true"); + } else { + System.out.println("toggleLoopingBorder called, set loopingBorder to false"); + } + } } From c478c296735f9a0cf496635551bf934d254c19c0 Mon Sep 17 00:00:00 2001 From: "guillaume.bonabau" Date: Wed, 10 Apr 2024 16:18:36 +0200 Subject: [PATCH 07/13] fixed typos, setCell(), removed countAround in Simulator, commented out getCell() in Simulator and updated clickCell to use the Table getCell.getValue --- src/backend/Cell.java | 6 +++--- src/backend/Simulator.java | 34 +++++----------------------------- 2 files changed, 8 insertions(+), 32 deletions(-) diff --git a/src/backend/Cell.java b/src/backend/Cell.java index cfd5a9e..a5aff96 100644 --- a/src/backend/Cell.java +++ b/src/backend/Cell.java @@ -1,10 +1,10 @@ package backend; public class Cell { - protected int value; - protected int density; + private int value; + private int density; - protected Cell(int value, int density) { + public Cell(int value, int density) { this.value = value; this.density = density; } diff --git a/src/backend/Simulator.java b/src/backend/Simulator.java index 88ae35a..3fc18f1 100644 --- a/src/backend/Simulator.java +++ b/src/backend/Simulator.java @@ -116,7 +116,6 @@ public class Simulator extends Thread { Table tempTable = new Table(this.height, this.width); for(int x=0; x>>>>>> 343c71dc317aee3d5caa32ac9b6c57dd3ac996bc /* you should distribute this action in methods/classes * don't write everything here ! @@ -157,8 +150,6 @@ public class Simulator extends Thread { - - } /* * leave this as is @@ -187,7 +178,7 @@ public class Simulator extends Thread { */ public void clickCell(int x, int y) { if (clickActionFlag) { - int currentCellValue = getCell(x, y); + int currentCellValue = table.getCell(x, y).getValue(); int newCellValue; if (currentCellValue == 0) { if (enableLogs) { @@ -213,10 +204,10 @@ public class Simulator extends Thread { * @param y coordinate of cell * @return value of cell */ - public int getCell(int x, int y) { + //public int getCell(int x, int y) { //TODO : complete method with proper return - return 0; - } + // return; + //} /** * * @return list of Animals in simulated world @@ -249,22 +240,7 @@ public class Simulator extends Thread { * @param val to set in cell */ 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 - } - - public void countAround(int x, int y) { - //enableLogs - //getCell - //if loopingBorder TRUE, border count as living. - if (loopingBorder == true){ - - } - else { - - } + this.table.getCell(x, y).setValue(val); } From ff0ad5968cddddb5d81ecbf22c19eefae0f07c91 Mon Sep 17 00:00:00 2001 From: Balthazar SQUINABOL Date: Wed, 10 Apr 2024 16:29:05 +0200 Subject: [PATCH 08/13] Actualiser src/windowInterface/MyInterface.java --- src/windowInterface/MyInterface.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/windowInterface/MyInterface.java b/src/windowInterface/MyInterface.java index f506362..34c46c0 100644 --- a/src/windowInterface/MyInterface.java +++ b/src/windowInterface/MyInterface.java @@ -393,6 +393,7 @@ public class MyInterface extends JFrame { } public void update (int stepCount) { + System.out.println("update called"); this.setStepBanner("Step : "+ stepCount); this.repaint(); } From 3598d99e4f245cd335c536cc9f86a57a58c9dd24 Mon Sep 17 00:00:00 2001 From: Balthazar SQUINABOL Date: Wed, 10 Apr 2024 16:29:32 +0200 Subject: [PATCH 09/13] Actualiser src/backend/Simulator.java --- src/backend/Simulator.java | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/src/backend/Simulator.java b/src/backend/Simulator.java index f8e45bd..d115462 100644 --- a/src/backend/Simulator.java +++ b/src/backend/Simulator.java @@ -226,19 +226,6 @@ public class Simulator extends Thread { int currentCellValue = getCell(x, y); // set cell value to !currentCellValue } - - public void countAround(int x, int y) { - //enableLogs - //getCell - //if loopingBorder TRUE, border count as living. - if (loopingBorder == true){ - - } - else { - - } - } - /** * @@ -302,7 +289,7 @@ public class Simulator extends Thread { public boolean isLoopingBorder() { //TODO : complete method with proper return - return false; + return loopingBorder; } public void toggleLoopingBorder() { From 2dae9a3251342b4717153eaa335adb8c6503f374 Mon Sep 17 00:00:00 2001 From: Balthazar SQUINABOL Date: Wed, 10 Apr 2024 16:29:57 +0200 Subject: [PATCH 10/13] Actualiser src/backend/Simulator.java --- src/backend/Simulator.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/backend/Simulator.java b/src/backend/Simulator.java index d115462..9dc43d2 100644 --- a/src/backend/Simulator.java +++ b/src/backend/Simulator.java @@ -288,12 +288,12 @@ public class Simulator extends Thread { } public boolean isLoopingBorder() { - //TODO : complete method with proper return + //ODO-COMPLETE : complete method with proper return return loopingBorder; } public void toggleLoopingBorder() { - //TODO : complete method + //ODO-COMPLETE : complete method loopingBorder = !loopingBorder; if (enableLogs) { if (loopingBorder) { From 37cdcde4c57f5bc05dea497b646cfad0f9ae38ee Mon Sep 17 00:00:00 2001 From: "balthazar.squinabol" Date: Wed, 10 Apr 2024 16:30:27 +0200 Subject: [PATCH 11/13] s --- src/backend/Simulator.java | 19 +++---------------- src/windowInterface/MyInterface.java | 1 + 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/src/backend/Simulator.java b/src/backend/Simulator.java index f8e45bd..9dc43d2 100644 --- a/src/backend/Simulator.java +++ b/src/backend/Simulator.java @@ -226,19 +226,6 @@ public class Simulator extends Thread { int currentCellValue = getCell(x, y); // set cell value to !currentCellValue } - - public void countAround(int x, int y) { - //enableLogs - //getCell - //if loopingBorder TRUE, border count as living. - if (loopingBorder == true){ - - } - else { - - } - } - /** * @@ -301,12 +288,12 @@ public class Simulator extends Thread { } public boolean isLoopingBorder() { - //TODO : complete method with proper return - return false; + //ODO-COMPLETE : complete method with proper return + return loopingBorder; } public void toggleLoopingBorder() { - //TODO : complete method + //ODO-COMPLETE : complete method loopingBorder = !loopingBorder; if (enableLogs) { if (loopingBorder) { diff --git a/src/windowInterface/MyInterface.java b/src/windowInterface/MyInterface.java index f506362..34c46c0 100644 --- a/src/windowInterface/MyInterface.java +++ b/src/windowInterface/MyInterface.java @@ -393,6 +393,7 @@ public class MyInterface extends JFrame { } public void update (int stepCount) { + System.out.println("update called"); this.setStepBanner("Step : "+ stepCount); this.repaint(); } From bbc93ac73c3dab311cbeb519f85eeb7b84abf843 Mon Sep 17 00:00:00 2001 From: "guillaume.bonabau" Date: Wed, 10 Apr 2024 16:43:14 +0200 Subject: [PATCH 13/13] fixed getCell --- src/backend/Simulator.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/backend/Simulator.java b/src/backend/Simulator.java index 3fc18f1..3cd1ca6 100644 --- a/src/backend/Simulator.java +++ b/src/backend/Simulator.java @@ -178,7 +178,7 @@ public class Simulator extends Thread { */ public void clickCell(int x, int y) { if (clickActionFlag) { - int currentCellValue = table.getCell(x, y).getValue(); + int currentCellValue = getCell(x, y); int newCellValue; if (currentCellValue == 0) { if (enableLogs) { @@ -204,10 +204,11 @@ public class Simulator extends Thread { * @param y coordinate of cell * @return value of cell */ - //public int getCell(int x, int y) { - //TODO : complete method with proper return - // return; - //} + public int getCell(int x, int y) { + //TODO-ERROR : WHY THE FUCK DOES IT WORK AT 0 BUT NOT WITH table.getcell.getvalue ???? + //complete method with proper return + return 0; + } /** * * @return list of Animals in simulated world