-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLocation.java
More file actions
99 lines (83 loc) · 2.61 KB
/
Copy pathLocation.java
File metadata and controls
99 lines (83 loc) · 2.61 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
94
95
96
97
98
99
import java.util.*;
public class Location {
private String locationName;
private String locationDescription;
private final ArrayList<String> locationPaths;
private final ArrayList<Entity> entityList = new ArrayList<>();
public Location(){
locationPaths = new ArrayList<>();
}
public void setLocationName(String name){
locationName = name;
}
public String getLocationName(){
return locationName;
}
public void setLocationDescription(String description){
locationDescription = description;
}
public String getLocationDescription(){
return locationDescription;
}
public ArrayList<Entity> getEntityList(){
return entityList;
}
// Sets the possible paths that the Player could follow from the current Location
public void setPaths(String path){
locationPaths.add(path);
}
public boolean isItAPath(String location){
if (locationPaths.contains(location)){
return true;
}
return false;
}
public void removePaths(String location){
if (isItAPath(location)){
locationPaths.remove(location);
}
}
// check for entity in the location
public boolean isEntityInLocation(String entity){
for (Entity entityObject : entityList){
if (entityObject.getName().equals(entity)){
return true;
}
}
return false;
}
public Entity getEntity(String entity){
for (Entity entityObject : entityList){
if (entityObject.getName().equals(entity)){
return entityObject;
}
}
return null;
}
// Removes an entity from the location
public void removeEntity(String entity){
entityList.removeIf(entityObject -> entityObject.getName().equals(entity));
}
public void createEntity(String name, String type, String description, GameModel model){
Entity newEntity = new Entity();
newEntity.setName(name);
newEntity.setType(type);
newEntity.setDescription(description);
model.setNewEntity(name, description, type);
entityList.add(newEntity);
}
public void addEntity(String name, GameModel model){
if (model.containsEntity(name)) {
Entity entity = model.getEntity(name);
entityList.add(entity);
}
}
public boolean containsEntity(String name){
for (Entity entity : entityList){
if (entity.getName().equals(name)){
return true;
}
}
return false;
}
}