diff --git a/src/backend/Cell.java b/src/backend/Cell.java index 0c0ec6e..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; } @@ -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 8826654..75efed1 100644 --- a/src/backend/Simulator.java +++ b/src/backend/Simulator.java @@ -26,9 +26,11 @@ 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; + private Table table; public Simulator(MyInterface mjfParam) { mjf = mjfParam; @@ -46,6 +48,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 +113,28 @@ 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; 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 ! * @@ -128,8 +151,6 @@ public class Simulator extends Thread { - - } /* * leave this as is @@ -185,7 +206,8 @@ public class Simulator extends Thread { * @return value of cell */ public int getCell(int x, int y) { - //TODO : complete method with proper return + //TODO-ERROR : WHY THE FUCK DOES IT WORK AT 0 BUT NOT WITH table.getcell.getvalue ???? + //complete method with proper return return 0; } /** @@ -237,7 +259,7 @@ public class Simulator extends Thread { } } - + /** * @@ -300,12 +322,20 @@ 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) { + System.out.println("toggleLoopingBorder called, set loopingBorder to true"); + } else { + System.out.println("toggleLoopingBorder called, set loopingBorder to false"); + } + } } @@ -316,6 +346,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 diff --git a/src/windowInterface/MyInterface.java b/src/windowInterface/MyInterface.java index 67ae441..34c46c0 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(); @@ -379,6 +393,7 @@ public class MyInterface extends JFrame { } public void update (int stepCount) { + System.out.println("update called"); this.setStepBanner("Step : "+ stepCount); this.repaint(); }