-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFarmController.java
69 lines (55 loc) · 2.36 KB
/
FarmController.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
58
59
60
61
62
63
64
65
66
67
68
69
package controller.farm;
import controller.GameController;
import controller.GameControllerState;
import controller.TimeConverter;
import controller.farm.element.WeatherController;
import controller.farm.element.building.*;
import model.InGameTime;
import model.Position;
import model.farm.Farm;
import model.farm.building.crop_field.CropField;
import model.farm.building.stockyard.Stockyard;
public abstract class FarmController implements GameControllerState {
protected final Farm farm;
protected final GameController controller;
private final TimeConverter timeConverter;
private final WeatherController weatherController;
public FarmController(FarmController farmController) {
this.farm = farmController.farm;
this.controller = farmController.controller;
this.timeConverter = farmController.timeConverter;
this.weatherController = farmController.weatherController;
}
public FarmController(Farm farm, GameController controller, long realSecToGameMinutesRate) {
this.farm = farm;
this.controller = controller;
this.timeConverter = new TimeConverter(realSecToGameMinutesRate);
this.weatherController = new WeatherController(this.farm);
}
public TimeConverter getTimeConverter() {
return this.timeConverter;
}
@Override
public void reactMouseMovement(Position position) {}
@Override
public void reactMouseClick(Position position) {}
@Override
public void reactTimePassed(long elapsedTimeSinceLastFrame) {
InGameTime elapsedTime = this.timeConverter.convert(elapsedTimeSinceLastFrame);
this.farm.setTime(this.farm.getTime().add(elapsedTime));
CropFieldController cropFieldController = new CropFieldController(this.controller, this.farm);
for (CropField cropField: this.farm.getBuildings().getCropFields()) {
cropFieldController.reactTimePassed(cropField, elapsedTime);
}
StockyardController stockyardController = new StockyardController(this.controller, this.farm);
for (Stockyard stockyard: this.farm.getBuildings().getStockyards()) {
stockyardController.reactTimePassed(stockyard, elapsedTime);
}
this.weatherController.reactTimePassed(elapsedTime);
}
public Farm getFarm() {
return this.farm;
}
@Override
public void reactChangeState() {}
}