Merge branch 'master' of https://gitarero.ecam.fr/laure.bel/OOP_F3_Project.git
This commit is contained in:
commit
e2bb167f2f
|
|
@ -1,4 +1,5 @@
|
|||
package backend;
|
||||
import java.awt.Color;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -224,12 +225,14 @@ 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) {
|
||||
if (clickActionFlag==0) { // cell
|
||||
world.setCell(x, y, getCell(x, y) == 1 ? 0 : 1);
|
||||
} else if (clickActionFlag==1) {
|
||||
|
||||
} else if (clickActionFlag==2) {
|
||||
|
||||
} else if (clickActionFlag==1) { // sheep
|
||||
Sheep sheep = new Sheep(x,y);
|
||||
agents.add(sheep);
|
||||
} else if (clickActionFlag==2) { // wolf
|
||||
Wolf wolf = new Wolf(x,y);
|
||||
agents.add(wolf);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,55 @@
|
|||
package backend;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
|
||||
public class Wolf extends Agent {
|
||||
|
||||
int hunger;
|
||||
Random rand;
|
||||
|
||||
Wolf(int x,int y){
|
||||
//first we call the constructor of the superClass(Animal)
|
||||
//with the values we want.
|
||||
// here we decide that a Sheep is initially white using this constructor
|
||||
super(x,y,Color.orange);
|
||||
// we give our sheep a hunger value of zero at birth
|
||||
hunger = 0;
|
||||
//we initialize the random number generator we will use to move randomly
|
||||
rand = new Random();
|
||||
}
|
||||
|
||||
/**
|
||||
* action of the animal
|
||||
* it can interact with the cells or with other animals
|
||||
* as you wish
|
||||
*/
|
||||
public boolean liveTurn(ArrayList<Agent> neighbors, World world) {
|
||||
if(world.getCell(x, y)==1) {
|
||||
world.setCell(x, y, 0);
|
||||
} else {
|
||||
hunger++;
|
||||
}
|
||||
this.moveRandom();
|
||||
return hunger>10;
|
||||
}
|
||||
|
||||
private void moveRandom() {
|
||||
int direction = rand.nextInt(4);
|
||||
if(direction == 0) {
|
||||
x+=1;
|
||||
}
|
||||
if(direction == 1) {
|
||||
y+=1;
|
||||
}
|
||||
if(direction == 2) {
|
||||
x-=1;
|
||||
}
|
||||
if(direction == 3) {
|
||||
y-=1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue