This commit is contained in:
Timéo 2024-05-29 14:05:35 +02:00
commit 9eb46f0c79
2 changed files with 24 additions and 8 deletions

View File

@ -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, Simulator world) { public boolean liveTurn(ArrayList<Agent> neighbors, World 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 {

View File

@ -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>();
@ -224,7 +224,13 @@ public class Simulator extends Thread {
* method called when clicking on a cell in the interface * method called when clicking on a cell in the interface
*/ */
public void clickCell(int x, int y) { public void clickCell(int x, int y) {
world.setCell(x, y, getCell(x, y) == 1 ? 0 : 1); if (clickActionFlag==0) {
world.setCell(x, y, getCell(x, y) == 1 ? 0 : 1);
} else if (clickActionFlag==1) {
} else if (clickActionFlag==2) {
}
} }
@ -358,10 +364,11 @@ public class Simulator extends Thread {
} }
public void toggleClickAction() { public void toggleClickAction() {
if (clickActionFlag() != 2) { if (clickActionFlag < 2) {
= ++ clickActionFlag ++ ;
}else if (clickActionFlag == 2) {
clickActionFlag=0;
} }
else = 0
} }
@ -385,7 +392,16 @@ 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
return "";
if (clickActionFlag==0) {
return "cell";
}else if (clickActionFlag==1) {
return "sheep";
}else if (clickActionFlag==2) {
return "wolf";
}else {
return "error";
}
} }