functional Cell and corresponding methods in Simulator -> worlds shows

This commit is contained in:
Raphaelsav 2024-04-27 17:51:01 +02:00
parent 2d83688930
commit bd09662ce6
2 changed files with 25 additions and 8 deletions

View File

@ -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;
}
}

View File

@ -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<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
@ -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);
}
/**