-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWorldProperty.java
More file actions
105 lines (90 loc) · 3.13 KB
/
Copy pathWorldProperty.java
File metadata and controls
105 lines (90 loc) · 3.13 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
100
101
102
103
104
105
package storygenerator;
import storyelements.StoryElement;
/**
*
* @author etienne
*/
public class WorldProperty {
public enum PropertyKey {
IS_ARMED, IS_DEAD, IS_DESTROYED, IS_CAPTIVE,
OWNS, IS_AT_LOCATION, LOVES, HATES, HAS_EQUIPPED, IS_PRISONER_OF
}
//This determines what kind of fact about the world this property is.
public PropertyKey aKey;
//These variables determine to what StoryElement(s) this property applies.
//There must be a subject, but not necessarily an object
//E.g. Subject OWNS Object
//E.g. Subject IS_DEAD [no object]
public StoryElement aSubject;
public StoryElement aObject;
//This is true if no actions can have an effect on the property.
//Then the property is either always true or always false.
public boolean aIsContext;
/*
* There are 4 constructors. If no context boolean is provided, the context boolean
* is set to false.
*/
public WorldProperty(StoryElement pSubject, PropertyKey pKey, StoryElement pObject) {
aKey = pKey;
aSubject = pSubject;
aObject = pObject;
aIsContext = false;
}
public WorldProperty(StoryElement pSubject, PropertyKey pKey) {
aKey = pKey;
aSubject = pSubject;
aObject = null;
aIsContext = false;
}
public WorldProperty(StoryElement pSubject, PropertyKey pKey, StoryElement pObject, boolean pIsContext) {
aKey = pKey;
aSubject = pSubject;
aObject = pObject;
aIsContext = pIsContext;
}
public WorldProperty(StoryElement pSubject, PropertyKey pKey, boolean pIsContext) {
aKey = pKey;
aSubject = pSubject;
aObject = null;
aIsContext = pIsContext;
}
@Override
public String toString() {
String s = aSubject.toString();
// switch(aKey) {
// case IS_AT_LOCATION: s = s + " is at the "; break;
// case IS_DEAD: s = s + " is dead."; break;
// default: s = s + " " + aKey.toString(); break;
// }
s = s + " " + aKey.toString();
if (aObject != null) {
s = s + " " + aObject.toString() + ".";
}
else {
s = s + ".";
}
return s;
}
@Override
public boolean equals(Object o) {
if (o == null) return false;
if (o == this) return true;
if (!(o instanceof WorldProperty)) return false;
WorldProperty w = (WorldProperty) o;
if (w.aKey == this.aKey && w.aSubject.equals(this.aSubject) &&
((w.aObject == null && this.aObject == null) ||
(w.aObject != null && this.aObject != null &&
w.aObject.equals(this.aObject)))){
return true;
}
else return false;
}
@Override
public int hashCode() {
int hash = 5;
hash = 79 * hash + (this.aKey != null ? this.aKey.hashCode() : 0);
hash = 79 * hash + (this.aSubject != null ? this.aSubject.hashCode() : 0);
hash = 79 * hash + (this.aObject != null ? this.aObject.hashCode() : 0);
return hash;
}
}