Cell Density
This commit is contained in:
parent
25c7bab182
commit
9c325932f5
|
|
@ -31,6 +31,7 @@ public class Simulator extends Thread {
|
|||
private int height;
|
||||
private boolean enableLogs;
|
||||
private Table table;
|
||||
private boolean cellDensityToggle;
|
||||
|
||||
public Simulator(MyInterface mjfParam) {
|
||||
mjf = mjfParam;
|
||||
|
|
@ -38,6 +39,7 @@ public class Simulator extends Thread {
|
|||
pauseFlag=false;
|
||||
loopingBorder=false;
|
||||
clickActionFlag=false;
|
||||
cellDensityToggle=true;
|
||||
|
||||
agents = new ArrayList<Agent>();
|
||||
fieldBirthValues = new ArrayList<Integer>();
|
||||
|
|
@ -180,19 +182,52 @@ public class Simulator extends Thread {
|
|||
public void clickCell(int x, int y) {
|
||||
if (clickActionFlag) {
|
||||
int currentCellValue = getCell(x, y);
|
||||
int newCellValue;
|
||||
if (currentCellValue == 0) {
|
||||
if (enableLogs) {
|
||||
System.out.println("clickCell Called, cell :" + x + "," + y + " is now alive");
|
||||
int newCellValue = 0;
|
||||
if(cellDensityToggle) {
|
||||
if (currentCellValue == -1) {
|
||||
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 {
|
||||
if (enableLogs) {
|
||||
System.out.println("clickCell Called, cell :" + x + "," + y + " is now dead");
|
||||
if (currentCellValue == 0) {
|
||||
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);
|
||||
} else {
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -60,17 +60,20 @@ public class JPanelDraw extends JPanel {
|
|||
for(int x=0; x<mySimu.getWidth();x++) {
|
||||
for (int y=0; y<mySimu.getHeight(); y++) {
|
||||
int cellContent = mySimu.getCell(x,y);
|
||||
if(cellContent == -1) {
|
||||
g.setColor(Color.gray);
|
||||
}
|
||||
if(cellContent == 0) {
|
||||
continue;
|
||||
}
|
||||
if(cellContent == 1) {
|
||||
g.setColor(Color.green);
|
||||
g.setColor(Color.white);
|
||||
}
|
||||
if(cellContent == 2) {
|
||||
g.setColor(Color.yellow);
|
||||
}
|
||||
if(cellContent == 3) {
|
||||
g.setColor(Color.cyan);
|
||||
g.setColor(Color.red);
|
||||
}
|
||||
g.fillRect(
|
||||
(int) Math.round(x*cellWidth),
|
||||
|
|
|
|||
Loading…
Reference in New Issue