This commit is contained in:
Balthazar SQUINABOL 2024-04-10 16:32:49 +02:00
commit 32937516e3
2 changed files with 46 additions and 13 deletions

View File

@ -1,10 +1,10 @@
package backend; package backend;
public class Cell { public class Cell {
protected int value; private int value;
protected int density; private int density;
protected Cell(int value, int density) { public Cell(int value, int density) {
this.value = value; this.value = value;
this.density = density; this.density = density;
} }
@ -15,10 +15,10 @@ public class Cell {
public int getDensity() { public int getDensity() {
return density; return density;
} }
public int setValue(int value) { public void setValue(int value) {
this.value = value; this.value = value;
} }
public int setDensity(int density){ public void setDensity(int density){
this.density = density; this.density = density;
} }
} }

View File

@ -30,6 +30,7 @@ public class Simulator extends Thread {
private int width; private int width;
private int height; private int height;
private boolean enableLogs; private boolean enableLogs;
private Table table;
public Simulator(MyInterface mjfParam) { public Simulator(MyInterface mjfParam) {
mjf = mjfParam; mjf = mjfParam;
@ -47,6 +48,7 @@ public class Simulator extends Thread {
this.width=COL_NUM; this.width=COL_NUM;
this.height=LINE_NUM; this.height=LINE_NUM;
enableLogs = true; // for debugging purposes enableLogs = true; // for debugging purposes
table = new Table(height, width);
//Default rule : Survive always, birth never //Default rule : Survive always, birth never
@ -111,8 +113,28 @@ public class Simulator extends Thread {
} }
} }
//then evolution of the field //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; x<width; x++) {
for(int y=0; y<height; y++) {
if (this.table.getCell(x, y).getValue()=1) {
if (table.countNear(x,y)<2) {
tempTable.getCell(x,y).setValue(0);
} else if(table.countNear(x,y)>3) {
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 /* you should distribute this action in methods/classes
* don't write everything here ! * don't write everything here !
* *
@ -129,8 +151,6 @@ public class Simulator extends Thread {
}
/* /*
* leave this as is * leave this as is
@ -159,7 +179,7 @@ public class Simulator extends Thread {
*/ */
public void clickCell(int x, int y) { public void clickCell(int x, int y) {
if (clickActionFlag) { if (clickActionFlag) {
int currentCellValue = getCell(x, y); int currentCellValue = table.getCell(x, y).getValue();
int newCellValue; int newCellValue;
if (currentCellValue == 0) { if (currentCellValue == 0) {
if (enableLogs) { if (enableLogs) {
@ -185,10 +205,10 @@ public class Simulator extends Thread {
* @param y coordinate of cell * @param y coordinate of cell
* @return value 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 //TODO : complete method with proper return
return 0; // return;
} //}
/** /**
* *
* @return list of Animals in simulated world * @return list of Animals in simulated world
@ -226,6 +246,19 @@ public class Simulator extends Thread {
int currentCellValue = getCell(x, y); int currentCellValue = getCell(x, y);
// set cell value to !currentCellValue // 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 {
}
}
/** /**
* *