-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFarm.java
138 lines (109 loc) · 3.34 KB
/
Farm.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
package model.farm;
import model.Position;
import model.InGameTime;
import model.farm.data.Livestock;
import model.farm.data.Weather;
import model.farm.entity.Entity;
import model.farm.data.item.Crop;
import model.farm.building.BuildingSet;
import model.farm.data.item.Item;
import model.region.RectangleRegion;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
public class Farm implements Serializable {
private Entity farmer;
private final BuildingSet buildings;
private InGameTime time;
private Inventory inventory;
private Wallet wallet;
private Weather currentWeather;
private final List<Weather> weatherTypes;
private final List<Crop> cropTypes;
private final List<Livestock> livestockTypes;
private final int width;
private final int height;
public Farm(int width, int height) {
this(width, height, new BuildingSet());
}
public Farm(int width, int height, BuildingSet buildings) {
this.width = width;
this.height = height;
this.buildings = buildings;
this.cropTypes = new ArrayList<>();
this.livestockTypes = new ArrayList<>();
this.weatherTypes = new ArrayList<>();
this.inventory = new Inventory();
}
public RectangleRegion getInsideRegion() {
return new RectangleRegion(new Position(1, 1), this.width - 2, this.height - 2);
}
public boolean isTraversable(Position position) {
return getInsideRegion().contains(position) && this.buildings.isTraversable(position);
}
public int getWidth() {
return this.width;
}
public int getHeight() {
return this.height;
}
public BuildingSet getBuildings() {
return this.buildings;
}
public void setCurrentWeather(Weather weather) {
this.currentWeather = weather;
}
public Weather getCurrentWeather() {
return this.currentWeather;
}
public void setFarmer(Entity farmer) {
this.farmer = farmer;
}
public Entity getFarmer() {
return this.farmer;
}
public void setInventory(Inventory inventory) {
this.inventory = inventory;
}
public Inventory getInventory() {
return this.inventory;
}
public void setTime(InGameTime time) {
this.time = time;
}
public InGameTime getTime() {
return this.time;
}
public void setWallet(Wallet wallet) {
this.wallet = wallet;
}
public Wallet getWallet() {
return this.wallet;
}
public void addCropTypes(List<Crop> crops) {
this.cropTypes.addAll(crops);
}
public List<Crop> getCropTypes() {
return this.cropTypes;
}
public void addLivestockTypes(List<Livestock> livestockTypes) {
this.livestockTypes.addAll(livestockTypes);
}
public List<Livestock> getLivestockTypes() {
return this.livestockTypes;
}
public List<Item> getAllItems() {
List<Item> items = new ArrayList<>();
items.addAll(this.cropTypes);
for (Livestock livestock: this.livestockTypes) {
items.add(livestock.getProducedItem());
}
return items;
}
public void addWeatherTypes(List<Weather> weathers) {
this.weatherTypes.addAll(weathers);
}
public List<Weather> getWeatherTypes() {
return this.weatherTypes;
}
}