-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathWorldItem.java
More file actions
87 lines (71 loc) · 1.98 KB
/
WorldItem.java
File metadata and controls
87 lines (71 loc) · 1.98 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
/*
* Spencer Caplan
*/
import java.util.*;
public class WorldItem {
private String myName = "";
private List<Feature> myFeatures = new ArrayList<Feature>();
private String levelHome = "";
public WorldItem(String name) {
myName = name;
}
/*
* For making a shallow copies of an existing WorldItem object
*/
public WorldItem(WorldItem toCopy) {
myName = toCopy.getName();
myFeatures = new ArrayList<Feature>(toCopy.getFeatures());
levelHome = toCopy.getLevelHome();
}
public String toString() {
return myName;
}
public void setLevelHome(String toSet) {
levelHome = toSet;
}
public void addFeature(Feature toAdd) {
myFeatures.add(toAdd);
}
public String getSuperFeatureName() {
for (Feature currFeature : myFeatures) {
if (currFeature.getLevel().equals("super")) {
return currFeature.getName();
}
}
return "";
}
public List<Feature> getFeatures() {
return myFeatures;
}
public Map<String, Feature> getFeatureMap() {
Map<String, Feature> toReturn = new HashMap<String, Feature>();
for (ListIterator<Feature> iter = myFeatures.listIterator(); iter.hasNext(); ) {
Feature currFeature = iter.next();
toReturn.put(currFeature.getName(), currFeature);
}
return toReturn;
}
public String getLevelHome() {
return levelHome;
}
public String getName() {
return myName;
}
public void printFeatures() {
System.out.println("Features for " + myName + ": ");
System.out.println("----------");
for (ListIterator<Feature> iter = myFeatures.listIterator(); iter.hasNext(); ) {
Feature currFeature = iter.next();
System.out.println(currFeature.getName() + " : " + currFeature.getLevel());
}
System.out.println("");
}
public void printFeaturesCompact() {
System.out.print(myName + ":");
for (ListIterator<Feature> iter = myFeatures.listIterator(); iter.hasNext(); ) {
Feature currFeature = iter.next();
System.out.print("(" + currFeature.getName() + "," + currFeature.getLevel() + "),");
}
System.out.println();
}
}