forked from RalfsGames/antGreenfoot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Queen.java
57 lines (50 loc) · 1.48 KB
/
Queen.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
import java.util.Random;
/**
* Created by Vincent Modrow on 26/02/2017.
* PACKAGE_NAME
*/
public class Queen extends Creature {
public static int PRICE = 10;
private static int maxANTSinHILL = 120;
private int LP = 1000;
private int randomLength;
/**
* Create an ant with a given home hill. The initial speed is zero (not moving).
*/
public Queen() {
randomLength = (new Random().nextInt(1010));
}
public void act() {
if (!checkLiveStat()) {
getWorld().removeObject(this);
} else {
if (randomLength <= 1) {
getWorld().removeObject(this);
spawnHill();
} else {
randomLength -= 1;
}
}
}
protected boolean checkLiveStat() {
if ((this.LP) > 0) {
// substract defined Value from LP
LP -= Ant.CALORIESBYSTEP;
randomWalk();
return Ant.IS_ALIVE;
} else {
return Ant.IS_DEAD;
}
}
private void spawnHill() {
if ((LP / randomLength) < Queen.maxANTSinHILL) {
//FIXME
getWorld().addObject(new AntHill(Queen.maxANTSinHILL, AntHill.DEFAULT_FOODVALUE), getX(), getY());
getWorld().removeObject(this);
} else {
//FIXME
getWorld().addObject(new AntHill(AntHill.DEFAULTNUMBER_ANTS, LP / randomLength), getX(), getY());
getWorld().removeObject(this);
}
}
}