diff --git a/src/backend/Cell.java b/src/backend/Cell.java index 0986c56..1e3d9b5 100644 --- a/src/backend/Cell.java +++ b/src/backend/Cell.java @@ -1,16 +1,21 @@ package backend; public class Cell { - int val; + int alive; private Simulator mySimu; - public Cell(int val) { - this.val = val; + public Cell(int alive) { + this.alive = alive; } - public int getVal() { - return val; + public int getAlive() { + return this.alive; + } + public void setAlive(int status) { + this.alive = status; } + + } diff --git a/src/backend/Simulator.java b/src/backend/Simulator.java index 98ed246..73d66e2 100644 --- a/src/backend/Simulator.java +++ b/src/backend/Simulator.java @@ -40,6 +40,15 @@ public class Simulator extends Thread { //TODO : add missing attribute initialization + //initialize grid with dead cells + for(int x=0; x <= getWidth();x++) { + ArrayList arrayCell = new ArrayList(); //initialise first dimension with ArrayLists + cells.add(arrayCell); + for(int y=0; y <= getHeight(); y++) { + Cell cell = new Cell(0); //create a dead cell + cells.get(x).add(cell); //assign dead cell to its position in second dimension array + } + } //Default rule : Survive always, birth never @@ -158,7 +167,8 @@ public class Simulator extends Thread { */ public int getCell(int x, int y) { //TODO : complete method with proper return - return 0; + int status = cells.get(x).get(y).getAlive(); + return status; } /** * @@ -191,8 +201,10 @@ public class Simulator extends Thread { * @param y coord of cell * @param val to set in cell */ - public void setCell(int x, int y, int val) { - //TODO : complete method + public void setCell(int x, int y, int status) { + //TODO : complete method + cells.get(x).get(y).setAlive(status); + } /**