This commit is contained in:
Timéo 2024-05-29 14:28:40 +02:00
commit 4d7f223e9d
1 changed files with 23 additions and 5 deletions

View File

@ -241,14 +241,32 @@ public class Simulator extends Thread {
* method called when clicking on a cell in the interface
*/
public void clickCell(int x, int y) {
if (clickActionFlag==0) { // cell
world.setCell(x, y, getCell(x, y) == 1 ? 0 : 1);
} else if (clickActionFlag==1) { // sheep
ArrayList<Agent> nearby=getNeighboringAnimals(x,y,1);
if (nearby.isEmpty()) {
Sheep sheep = new Sheep(x,y);
agents.add(sheep);
}else {
for (Agent animal:nearby) {
agents.remove(animal);
}
}
} else if (clickActionFlag==2) { // wolf
ArrayList<Agent> nearby=getNeighboringAnimals(x,y,1);
if (nearby.isEmpty()) {
Wolf wolf = new Wolf(x,y);
agents.add(wolf);
}else {
for (Agent animal:nearby) {
agents.remove(animal);
}
}
}
}