-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMandrake.java
More file actions
55 lines (48 loc) · 1.55 KB
/
Mandrake.java
File metadata and controls
55 lines (48 loc) · 1.55 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
import java.util.List;
/**
* A simple model of a mandrake.
*
* @author Saathveekan Satheshkumar and Manik Aggarwal
* @version 2022.03.02 (2)
*/
public class Mandrake extends Plant {
private String PLANT_NAME;
/**
* Create a new mandrake. A mandrake may be created with age
* zero (a newborn) or with a random age.
*
* @param field The field currently occupied.
* @param location The location within the field.
* @param plantName The name of the plant.
*/
protected Mandrake(boolean randomAge, Field field, Location location, String plantName) {
super(field, location, plantName);
PLANT_NAME = plantName;
setAge(randomAge);
growthRate = 1.5;
currentFoodValue = data.getFoodValue(PLANT_NAME);
}
/**
* @return Mandrake does not need to find food.
*/
@Override
protected Location findFood() {
return null;
}
/**
* Check whether this mandrake is to give birth at this step.
* New births will be made into free adjacent locations.
* @param newPlant A list to return newly born mandrakes.
*/
@Override
protected void giveBirth(List<Animal> newPlant) {
Field field = getField();
List<Location> free = field.getFreeAdjacentLocations(getLocation());
int births = breed();
for(int b = 0; b < births && !free.isEmpty(); b++) {
Location loc = free.remove(0);
Mandrake young = new Mandrake(false, field, loc, PLANT_NAME);
newPlant.add(young);
}
}
}