Merge branch 'main' of https://gitarero.ecam.fr/guillaume.bonabau/OOP_F1_Project
This commit is contained in:
commit
a7fcc0f9a1
|
|
@ -7,8 +7,8 @@ public class Simulator extends Thread {
|
||||||
|
|
||||||
private MyInterface mjf;
|
private MyInterface mjf;
|
||||||
|
|
||||||
private final int COL_NUM = 10;
|
private final int COL_NUM = 100;
|
||||||
private final int LINE_NUM = 10;
|
private final int LINE_NUM = 100;
|
||||||
private final int LIFE_TYPE_NUM = 4;
|
private final int LIFE_TYPE_NUM = 4;
|
||||||
//Conway Radius : 1
|
//Conway Radius : 1
|
||||||
private final int LIFE_AREA_RADIUS = 1;
|
private final int LIFE_AREA_RADIUS = 1;
|
||||||
|
|
@ -31,6 +31,7 @@ public class Simulator extends Thread {
|
||||||
private int height;
|
private int height;
|
||||||
private boolean enableLogs;
|
private boolean enableLogs;
|
||||||
private Table table;
|
private Table table;
|
||||||
|
private boolean cellDensityToggle;
|
||||||
|
|
||||||
public Simulator(MyInterface mjfParam) {
|
public Simulator(MyInterface mjfParam) {
|
||||||
mjf = mjfParam;
|
mjf = mjfParam;
|
||||||
|
|
@ -49,6 +50,8 @@ public class Simulator extends Thread {
|
||||||
this.height=LINE_NUM;
|
this.height=LINE_NUM;
|
||||||
enableLogs = true; // for debugging purposes
|
enableLogs = true; // for debugging purposes
|
||||||
table = new Table(height, width, this);
|
table = new Table(height, width, this);
|
||||||
|
cellDensityToggle=false;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Default rule : Survive always, birth never
|
//Default rule : Survive always, birth never
|
||||||
|
|
@ -180,19 +183,52 @@ 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 = getCell(x, y);
|
||||||
int newCellValue;
|
int newCellValue = 0;
|
||||||
if (currentCellValue == 0) {
|
if(cellDensityToggle) {
|
||||||
if (enableLogs) {
|
if (currentCellValue == -1) {
|
||||||
System.out.println("clickCell Called, cell :" + x + "," + y + " is now alive");
|
newCellValue = 0;
|
||||||
|
if (enableLogs) {
|
||||||
|
System.out.println("clickCell Called, cell :" + x + "," + y + " is now" + newCellValue + "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (currentCellValue == 0) {
|
||||||
|
newCellValue = 1;
|
||||||
|
if (enableLogs) {
|
||||||
|
System.out.println("clickCell Called, cell :" + x + "," + y + " is now" + newCellValue + "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (currentCellValue == 1) {
|
||||||
|
newCellValue = 2;
|
||||||
|
if (enableLogs) {
|
||||||
|
System.out.println("clickCell Called, cell :" + x + "," + y + " is now" + newCellValue + "");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
newCellValue = 1; // If the cell is dead, make it alive
|
if (currentCellValue == 2) {
|
||||||
|
newCellValue = 3;
|
||||||
|
if (enableLogs) {
|
||||||
|
System.out.println("clickCell Called, cell :" + x + "," + y + " is now" + newCellValue + "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (currentCellValue == 3) {
|
||||||
|
newCellValue = -1;
|
||||||
|
if (enableLogs) {
|
||||||
|
System.out.println("clickCell Called, cell :" + x + "," + y + " is now" + newCellValue + "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.setCell(x, y, newCellValue);
|
||||||
} else {
|
} else {
|
||||||
if (enableLogs) {
|
if (currentCellValue == 0) {
|
||||||
System.out.println("clickCell Called, cell :" + x + "," + y + " is now dead");
|
if (enableLogs) {
|
||||||
|
System.out.println("clickCell Called, cell :" + x + "," + y + " is now" + newCellValue + "");
|
||||||
|
}
|
||||||
|
newCellValue = 1;
|
||||||
|
} else {
|
||||||
|
if (enableLogs) {
|
||||||
|
System.out.println("clickCell Called, cell :" + x + "," + y + " is now" + newCellValue + "");
|
||||||
|
}
|
||||||
|
newCellValue = 0;
|
||||||
}
|
}
|
||||||
newCellValue = 0; // If the cell is alive, make it dead
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setCell(x, y, newCellValue);
|
this.setCell(x, y, newCellValue);
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
|
|
@ -269,6 +305,7 @@ public class Simulator extends Thread {
|
||||||
* @param lines of file representing saved world state
|
* @param lines of file representing saved world state
|
||||||
*/
|
*/
|
||||||
public void loadSaveState(ArrayList<String> lines) {
|
public void loadSaveState(ArrayList<String> lines) {
|
||||||
|
System.out.println("loadSaveState called");
|
||||||
/*
|
/*
|
||||||
* First some checks that the file is usable
|
* First some checks that the file is usable
|
||||||
* We call early returns in conditions like this
|
* We call early returns in conditions like this
|
||||||
|
|
@ -289,8 +326,11 @@ public class Simulator extends Thread {
|
||||||
*/
|
*/
|
||||||
for(int y =0; y<lines.size();y++) {
|
for(int y =0; y<lines.size();y++) {
|
||||||
String line = lines.get(y);
|
String line = lines.get(y);
|
||||||
|
System.out.println("line : " + line);
|
||||||
String[] lineElements = line.split(";");
|
String[] lineElements = line.split(";");
|
||||||
for(int x=0; x<lineElements.length;x++) {
|
for(int x=0; x<lineElements.length;x++) {
|
||||||
|
System.out.println("x : " + x);
|
||||||
|
System.out.println("lineElements : " + lineElements[x]);
|
||||||
String elem = lineElements[x];
|
String elem = lineElements[x];
|
||||||
int value = Integer.parseInt(elem);
|
int value = Integer.parseInt(elem);
|
||||||
setCell(x, y, value);
|
setCell(x, y, value);
|
||||||
|
|
|
||||||
|
|
@ -93,9 +93,6 @@ public class Table {
|
||||||
System.out.println("Created a random field");
|
System.out.println("Created a random field");
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO : load(filepath) turn a loaded saveable file into a table
|
|
||||||
//TODO : save(filename) turn the table into saveable file
|
|
||||||
|
|
||||||
public void serialPrint(){
|
public void serialPrint(){
|
||||||
for (int i = 0; i < height; i++) {
|
for (int i = 0; i < height; i++) {
|
||||||
System.out.print("\n");
|
System.out.print("\n");
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,6 @@ public class JPanelDraw extends JPanel {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setSimu(Simulator simu) {
|
public void setSimu(Simulator simu) {
|
||||||
mySimu = simu;
|
mySimu = simu;
|
||||||
}
|
}
|
||||||
|
|
@ -60,17 +59,20 @@ public class JPanelDraw extends JPanel {
|
||||||
for(int x=0; x<mySimu.getWidth();x++) {
|
for(int x=0; x<mySimu.getWidth();x++) {
|
||||||
for (int y=0; y<mySimu.getHeight(); y++) {
|
for (int y=0; y<mySimu.getHeight(); y++) {
|
||||||
int cellContent = mySimu.getCell(x,y);
|
int cellContent = mySimu.getCell(x,y);
|
||||||
|
if(cellContent == -1) {
|
||||||
|
g.setColor(Color.gray);
|
||||||
|
}
|
||||||
if(cellContent == 0) {
|
if(cellContent == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(cellContent == 1) {
|
if(cellContent == 1) {
|
||||||
g.setColor(Color.green);
|
g.setColor(Color.white);
|
||||||
}
|
}
|
||||||
if(cellContent == 2) {
|
if(cellContent == 2) {
|
||||||
g.setColor(Color.yellow);
|
g.setColor(Color.yellow);
|
||||||
}
|
}
|
||||||
if(cellContent == 3) {
|
if(cellContent == 3) {
|
||||||
g.setColor(Color.cyan);
|
g.setColor(Color.red);
|
||||||
}
|
}
|
||||||
g.fillRect(
|
g.fillRect(
|
||||||
(int) Math.round(x*cellWidth),
|
(int) Math.round(x*cellWidth),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue