functional Cell and corresponding methods in Simulator -> worlds shows
This commit is contained in:
parent
2d83688930
commit
bd09662ce6
|
|
@ -1,16 +1,21 @@
|
||||||
package backend;
|
package backend;
|
||||||
|
|
||||||
public class Cell {
|
public class Cell {
|
||||||
int val;
|
int alive;
|
||||||
private Simulator mySimu;
|
private Simulator mySimu;
|
||||||
|
|
||||||
public Cell(int val) {
|
public Cell(int alive) {
|
||||||
this.val = val;
|
this.alive = alive;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public int getVal() {
|
public int getAlive() {
|
||||||
return val;
|
return this.alive;
|
||||||
|
}
|
||||||
|
public void setAlive(int status) {
|
||||||
|
this.alive = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,15 @@ public class Simulator extends Thread {
|
||||||
|
|
||||||
//TODO : add missing attribute initialization
|
//TODO : add missing attribute initialization
|
||||||
|
|
||||||
|
//initialize grid with dead cells
|
||||||
|
for(int x=0; x <= getWidth();x++) {
|
||||||
|
ArrayList<Cell> arrayCell = new ArrayList<Cell>(); //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
|
//Default rule : Survive always, birth never
|
||||||
|
|
@ -158,7 +167,8 @@ public class Simulator extends Thread {
|
||||||
*/
|
*/
|
||||||
public int getCell(int x, int y) {
|
public int getCell(int x, int y) {
|
||||||
//TODO : complete method with proper return
|
//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 y coord of cell
|
||||||
* @param val to set in cell
|
* @param val to set in cell
|
||||||
*/
|
*/
|
||||||
public void setCell(int x, int y, int val) {
|
public void setCell(int x, int y, int status) {
|
||||||
//TODO : complete method
|
//TODO : complete method
|
||||||
|
cells.get(x).get(y).setAlive(status);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue