-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlant.java
More file actions
93 lines (70 loc) · 2.58 KB
/
Plant.java
File metadata and controls
93 lines (70 loc) · 2.58 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
import java.util.List;
/**
* Lays out the basic functions for a plant.
*
* @author Saathveekan Satheshkumar, Manik Aggarwal
* @version 2022.03.02 (2)
*/
public class Plant extends Animal {
//a growth multiplier
protected double growthRate;
//the current food value of the plant due to the growth rate
protected double currentFoodValue;
// the max food value for a plant
protected int maxTotalFoodValue = 50;
/**
* Create a new plant at a given location.
*
* @param field The field currently occu
* @param location The location within the field.
* @param plantName The name of the animal
*/
protected Plant(Field field, Location location, String plantName) {
super(field, location, plantName);
}
/**
* This is what the plant does most of the time: it gives birth and increases its food value during the day.
* In the process, it may die of old age.
*
* @param newPlant A list to return newly born animals.
* @param dayOfTime if true, then it is day. if false, then night
* @param currentWeather the current weather
*/
public void act(List<Animal> newPlant, boolean dayOfTime, String currentWeather) {
incrementAge();
if (isAlive()) {
giveBirth(newPlant);
// if it is sunny, then the current food value is increased at even faster rate ( 2 times the growth rate).
if (currentWeather.equals("Sunny") && currentFoodValue < maxTotalFoodValue / growthRate * 2) {
currentFoodValue = currentFoodValue * growthRate * 2;
}
//If it is rainy, then the current food value is increased at an even faster rate (1.5 times the growth rate).
else if (currentWeather.equals("Rainy") && currentFoodValue < maxTotalFoodValue / growthRate * 1.5) {
currentFoodValue = currentFoodValue * growthRate * 1.5;
}
// if it is day, then the current food value is multiplied by the growth rate.
else if (dayOfTime && currentFoodValue < maxTotalFoodValue / growthRate) {
currentFoodValue = currentFoodValue * growthRate;
}
}
}
/**
* Plants don't need to find
*/
@Override
protected Location findFood() {
return null;
}
/**
* Done in subclasses.
*/
@Override
protected void giveBirth(List<Animal> newPlant) {
}
/**
* @return returns the current food value.
*/
protected double getCurrentFoodValue() {
return currentFoodValue;
}
}