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 9dc43d2..e15240e 100644 --- a/src/backend/Simulator.java +++ b/src/backend/Simulator.java @@ -30,6 +30,7 @@ public class Simulator extends Thread { private int width; private int height; private boolean enableLogs; + private Table table; public Simulator(MyInterface mjfParam) { mjf = mjfParam; @@ -47,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 @@ -111,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 ! * @@ -129,8 +151,6 @@ public class Simulator extends Thread { - - } /* * leave this as is @@ -159,7 +179,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) { @@ -185,10 +205,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 @@ -226,6 +246,19 @@ 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 { + + } + } + /** *