when cliking on an animal it remove itself from the board like the cells
This commit is contained in:
parent
a426e87da4
commit
377ff8e633
|
|
@ -225,15 +225,33 @@ 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) {
|
||||||
|
|
||||||
if (clickActionFlag==0) { // cell
|
if (clickActionFlag==0) { // cell
|
||||||
world.setCell(x, y, getCell(x, y) == 1 ? 0 : 1);
|
world.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);
|
||||||
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()) {
|
||||||
}
|
Wolf wolf = new Wolf(x,y);
|
||||||
|
agents.add(wolf);
|
||||||
|
}else {
|
||||||
|
for (Agent animal:nearby) {
|
||||||
|
agents.remove(animal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue