Merge pull request 'dev_bnb' (#2) from dev_bnb into main

Reviewed-on: #2
This commit is contained in:
Guillaume BONABAU 2024-04-10 16:25:50 +02:00
commit fd4508b370
2 changed files with 34 additions and 29 deletions

View File

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

View File

@ -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,7 +113,27 @@ 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; 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
* don't write everything here !
@ -130,8 +152,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
@ -221,22 +241,7 @@ public class Simulator extends Thread {
* @param val to set in cell
*/
public void setCell(int x, int y, int val) {
//TODO : complete method
//j'ai ajouté une base, mais manque la partie qui modifie la valeur de la cellule
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 {
}
this.table.getCell(x, y).setValue(val);
}