-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCow.java
More file actions
55 lines (48 loc) · 1011 Bytes
/
Cow.java
File metadata and controls
55 lines (48 loc) · 1011 Bytes
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
//represents farm objects
public class Cow extends FarmObject{
private String name;
private int hungriness;
private int age;
private int sicknessLevel;
private int x;
private int y;
//constructs a cow with the given name and coordinates
public class Cow(String name, int x, int y){
this.name = name;
this.x = x;
this.y = y;
hungriness = 0;
age = 0;
sickness = 0;
}
//method to move the cow
public static void move(){
if(time > 6 && time < 18){
this.x = x -1 + Math.rand(2);
this.y = y -1 + Math.rand(2);
}
}
//x coordinate
public static int getX(){
return this.x;
}
//y coordinate
public static int getY(){
return this.y;
}
//eats grass
public static eatGrass(grass){
grass = Math.rand(9) + 1;
hungriness -= grass;
}
//removes cows after they die
public static testForDeath() {
if (hungriness >= 100 || age >= 90001) {
remove();
}
double chance = 0.0001 * age * sicknessLevel;
if (Math.random() < chance) {
removeObject();
}
}
}