dev_bnb #2
|
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,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;
|
||||||
|
|
@ -46,6 +47,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
|
||||||
|
|
@ -110,8 +112,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 !
|
||||||
*
|
*
|
||||||
|
|
@ -128,8 +150,6 @@ public class Simulator extends Thread {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* leave this as is
|
* leave this as is
|
||||||
|
|
@ -158,7 +178,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) {
|
||||||
|
|
@ -184,10 +204,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
|
||||||
|
|
@ -220,22 +240,7 @@ public class Simulator extends Thread {
|
||||||
* @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 val) {
|
||||||
//TODO : complete method
|
this.table.getCell(x, y).setValue(val);
|
||||||
//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 {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue