-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnimal.java
More file actions
105 lines (102 loc) · 2.37 KB
/
Animal.java
File metadata and controls
105 lines (102 loc) · 2.37 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package snow;
public class Animal {
public boolean alive;
public int age; //ticks alive
public int agemax; //maximum ticks in which animal can be active
public int timeWithoutFood; //ticks without having eaten
public int reproductionTime; //ticks needed to bear children
public int timeWithoutReproduction; //ticks without having children
public int fertility; //children born per reproduction
public int posx; //position in world-array
public int posy;
public int speed; //distance which can be travelled; helps to hunt(fox) or to find food (rabbit)
private int [] genome; //boni obtained by evolution
public boolean hasEaten; //if animal has consumed food in his life
public Animal(boolean a, int ag,int agmax, int twf,int twr, int rt, int f, int px, int py, int s, int[]g, boolean he){
alive=a;
age=ag;
agemax=agmax;
timeWithoutFood=twf;
timeWithoutReproduction=twr;
reproductionTime=rt;
fertility=f;
posx=px;
posy=py;
speed=s;
genome=g;
hasEaten=he;
}
public boolean getAlive(){
return alive;
}
public void setAlive(boolean a){
alive=a;
}
public boolean getHasEaten(){
return hasEaten;
}
public void setHasEaten(boolean a){
hasEaten=a;
}
public int getReproductionTime(){
return reproductionTime+genome[2]/4;
}
public void setReproductionTime(int n){
reproductionTime=n+genome[2]/4;
}
public int getTimeWithoutReproduction(){
return timeWithoutReproduction;
}
public void setTimeWithoutReproduction(int n){
timeWithoutReproduction=n;
}
public int getFertility(){
return fertility+genome[3]/3;
}
public void setFertility(int n){
fertility=n+genome[3]/3;
}
public int getPosx(){
return posx;
}
public void setPosx(int n){
posx=n;
}
public int getAge(){
return age;
}
public void setAge(int n){
age=n;
}
public int getAgemax(){
return agemax;
}
public void setAgemax(int n){
agemax=n;
}
public int getSpeed(){
return speed+genome[4]/3;
}
public void setSpeed(int n){
speed=n+genome[4]/3;
}
public int getTimeWithoutFood(){
return timeWithoutFood;
}
public void setTimeWithoutFood(int n){
timeWithoutFood=n;
}
public int[] getGenome(){
return genome;
}
public void setGenome(int []a){
genome=a;
}
public boolean die (){
if((age>agemax+genome[0]/3)||(timeWithoutFood>3-genome[1]/3)){ //sets alive on false if certain criteria are given
alive=false;
return true;
}
return false;
}
}