click action name the start
This commit is contained in:
parent
a16b1691d3
commit
d866f7c6f1
|
|
@ -29,7 +29,7 @@ public class Sheep extends Agent {
|
||||||
* it can interact with the cells or with other animals
|
* it can interact with the cells or with other animals
|
||||||
* as you wish
|
* as you wish
|
||||||
*/
|
*/
|
||||||
public boolean liveTurn(ArrayList<Agent> neighbors, World world) {
|
public boolean liveTurn(ArrayList<Agent> neighbors, Simulator world) {
|
||||||
if(world.getCell(x, y)==1) {
|
if(world.getCell(x, y)==1) {
|
||||||
world.setCell(x, y, 0);
|
world.setCell(x, y, 0);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ public class Simulator extends Thread {
|
||||||
private boolean stopFlag;
|
private boolean stopFlag;
|
||||||
private boolean pauseFlag;
|
private boolean pauseFlag;
|
||||||
private boolean loopingBorder;
|
private boolean loopingBorder;
|
||||||
private boolean clickActionFlag;
|
private int clickActionFlag;
|
||||||
private int loopDelay = 150;
|
private int loopDelay = 150;
|
||||||
private int[][] worldGrid;
|
private int[][] worldGrid;
|
||||||
private World world; //get the World instance
|
private World world; //get the World instance
|
||||||
|
|
@ -45,7 +45,7 @@ public class Simulator extends Thread {
|
||||||
//stopFlag=false; //not necessary since i set the state when pressing the button start
|
//stopFlag=false; //not necessary since i set the state when pressing the button start
|
||||||
pauseFlag=false;
|
pauseFlag=false;
|
||||||
loopingBorder=false;
|
loopingBorder=false;
|
||||||
clickActionFlag=false;
|
clickActionFlag=0;
|
||||||
|
|
||||||
agents = new ArrayList<Agent>();
|
agents = new ArrayList<Agent>();
|
||||||
fieldBirthValues = new ArrayList<Integer>();
|
fieldBirthValues = new ArrayList<Integer>();
|
||||||
|
|
@ -141,7 +141,7 @@ public class Simulator extends Thread {
|
||||||
// in agent classes
|
// in agent classes
|
||||||
|
|
||||||
|
|
||||||
int[][] newWorld = new int[getWidth()][getHeight()];
|
// int[][] newWorld = new int[getWidth()][getHeight()];
|
||||||
|
|
||||||
/*ArrayList<Agent> newAgents = new ArrayList<>();
|
/*ArrayList<Agent> newAgents = new ArrayList<>();
|
||||||
for(Agent agent : agents) {
|
for(Agent agent : agents) {
|
||||||
|
|
@ -149,32 +149,29 @@ public class Simulator extends Thread {
|
||||||
this.getNeighboringAnimals(
|
this.getNeighboringAnimals(
|
||||||
agent.getX(),
|
agent.getX(),
|
||||||
agent.getY(),
|
agent.getY(),
|
||||||
ANIMAL_AREA_RADIUS);}
|
ANIMAL_AREA_RADIUS);
|
||||||
if(!agent.liveTurn(
|
if(!agent.liveTurn(
|
||||||
neighbors,
|
neighbors,
|
||||||
this)) {
|
this)) {
|
||||||
agents.remove(agent);
|
agents.remove(agent);
|
||||||
}*/
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
|
|
||||||
// Apply Game of Life rules
|
// Apply Game of Life rules
|
||||||
//for (int x = 0; x < getWidth(); x++) {
|
/*for (int x = 0; x < getWidth(); x++) {
|
||||||
// for (int y = 0; y < getHeight(); y++) {
|
for (int y = 0; y < getHeight(); y++) {
|
||||||
// int aliveNeighbors = countAliveNeighbors(x, y);
|
int aliveNeighbors = countAliveNeighbors(x, y);
|
||||||
// if (world[x][y] == 1) {
|
if (getCell(x,y) == 1) { //
|
||||||
// newWorld[x][y] = (aliveNeighbors < 2 || aliveNeighbors > 3) ? 0 : 1;
|
newWorld[x][y] = (aliveNeighbors < 2 || aliveNeighbors > 3) ? 0 : 1;
|
||||||
// } else {
|
} else {
|
||||||
// newWorld[x][y] = (aliveNeighbors == 3) ? 1 : 0;
|
newWorld[x][y] = (aliveNeighbors == 3) ? 1 : 0;
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
//}
|
}
|
||||||
|
|
||||||
|
this.world = setWorld(newWorld,getWidth(),getHeight()) ;
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
//world = newWorld;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//then evolution of the field
|
//then evolution of the field
|
||||||
|
|
@ -320,7 +317,7 @@ public class Simulator extends Thread {
|
||||||
ArrayList<String> rule = new ArrayList<>();
|
ArrayList<String> rule = new ArrayList<>();
|
||||||
for (int i = 0; i < getHeight(); i++) {
|
for (int i = 0; i < getHeight(); i++) {
|
||||||
StringBuilder lineState = new StringBuilder();
|
StringBuilder lineState = new StringBuilder();
|
||||||
for (int j = 0 ; j < getHeight() ; j++) { // je crois qu'il y a un probleme, il fau+t mettre getWidth je crois
|
for (int j = 0 ; j < getHeight() ; j++) {
|
||||||
lineState.append(getCell(i, j));
|
lineState.append(getCell(i, j));
|
||||||
if (j < getWidth() - 1) {
|
if (j < getWidth() - 1) {
|
||||||
lineState.append(";");
|
lineState.append(";");
|
||||||
|
|
@ -382,6 +379,11 @@ public class Simulator extends Thread {
|
||||||
public String clickActionName() {
|
public String clickActionName() {
|
||||||
// TODO : initially return "sheep" or "cell"
|
// TODO : initially return "sheep" or "cell"
|
||||||
// depending on clickActionFlag
|
// depending on clickActionFlag
|
||||||
|
if (clickActionFlag==0) {
|
||||||
|
return "cell";
|
||||||
|
}else if (clickActionFlag==1) {
|
||||||
|
|
||||||
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue