-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlanted.java
50 lines (42 loc) · 1.39 KB
/
Planted.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
package model.farm.building.crop_field.state;
import model.InGameTime;
import model.farm.building.crop_field.CropField;
import model.farm.data.item.Crop;
public class Planted implements CropFieldState {
private final CropField cropField;
private final Crop crop;
private InGameTime timeRemaining;
private double harvestAmount; // double so that fractional changes may add up and have an effect
public Planted(CropField cropField, Crop crop) {
this.cropField = cropField;
this.crop = crop;
this.harvestAmount = this.crop.getBaseHarvestAmount();
this.timeRemaining = this.crop.getGrowTime();
}
@Override
public InGameTime getRemainingTime() {
return this.timeRemaining;
}
@Override
public void setRemainingTime(InGameTime time) {
this.timeRemaining = time;
if (this.timeRemaining.getMinute() <= 0) {
this.cropField.setState(new ReadyToHarvest(this.cropField, this.crop, this.harvestAmount));
}
}
@Override
public Crop getCrop() {
return this.crop;
}
@Override
public int getHarvestAmount() {
return (int) this.harvestAmount;
}
@Override
public void changeHarvestAmount(double harvestAmount) {
this.harvestAmount += harvestAmount;
if (this.harvestAmount <= 0) {
this.cropField.setState(new NotPlanted());
}
}
}