can delete agent went click on it
This commit is contained in:
parent
bb8896a31e
commit
381d12f021
|
|
@ -201,11 +201,25 @@ public class Simulator extends Thread {
|
||||||
if (clickActionFlag==0) { // cell
|
if (clickActionFlag==0) { // cell
|
||||||
setCell(x, y, getCell(x, y) == 1 ? 0 : 1);
|
setCell(x, y, getCell(x, y) == 1 ? 0 : 1);
|
||||||
} else if (clickActionFlag==1) { // sheep
|
} else if (clickActionFlag==1) { // sheep
|
||||||
Sheep sheep = new Sheep(x,y);
|
ArrayList<Agent> nearby=getNeighboringAnimals(x,y,1); //look if the cell has an agent
|
||||||
agents.add(sheep);
|
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
|
} else if (clickActionFlag==2) { // wolf
|
||||||
Wolf wolf = new Wolf(x,y);
|
ArrayList<Agent> nearby=getNeighboringAnimals(x,y,1);
|
||||||
agents.add(wolf);
|
if (nearby.isEmpty()) {
|
||||||
|
Sheep sheep = new Sheep(x,y);
|
||||||
|
agents.add(sheep);
|
||||||
|
}else {
|
||||||
|
for (Agent animal:nearby) {
|
||||||
|
agents.remove(animal);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue