-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFox.java
69 lines (51 loc) · 1.34 KB
/
Fox.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
public class Fox extends Animal
{
private int lastAteSteps=0;
public boolean isRabbit(){
return false;
}
public boolean timeToBreed(){
if((getCell().getAnimal().getTotalSurvivalSteps()>0) && (getCell().getAnimal().getTotalSurvivalSteps()%8==0)){
return true;
}
return false;
}
public void becomeEaten(){
}
public Fox giveBirth(){
Fox fox = new Fox();
return fox;
}
public void move(){
boolean found=false;
for (int i=0; i<getCell().getNeighborcells().size() && found==false; i++) {
if(getCell().getNeighborcells().get(i).containsRabbit(getCell().getNeighborcells().get(i))){
found=true;
Cell cellContainsRabbit=getCell().getNeighborcells().get(i);
Cell cellContainsFox=getCell();
cellContainsRabbit.getAnimal().becomeEaten();
cellContainsRabbit.setAnimal(cellContainsFox.getAnimal());
cellContainsFox.getAnimal().setCell(cellContainsRabbit);
cellContainsFox.getAnimal().survived();
cellContainsFox.setAnimal(null);
this.lastAteSteps=0;
}
}
if (!found) {
this.lastAteSteps++;
getCell().getAnimal().randomMove();
}
}
public boolean starve(){
if(this.lastAteSteps>3){
getCell().setAnimal(null);
return true;
}
return false;
}
public String toString(){
return "X";
}
}
//ONOMA: MARINA PAPAGEORGIOU
//AM: 4757