-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMapObject.java
241 lines (200 loc) · 5.91 KB
/
MapObject.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
package my.quarker;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.util.ArrayList;
/**
*
* @author ehoward
*/
public class MapObject {
private TerrainObject flooring; //should be either a wall or floor or stairs
private MonsterObject monster;
private ArrayList<ItemObject> items;
private Boolean changed = true;
public MapObject() {
}
public MapObject(TerrainObject floor) {
this(floor, null);
}
public MapObject(TerrainObject base, MonsterObject monster) {
flooring = base;
this.monster = monster;
items = null;
}
public MapObject(TerrainObject base, MonsterObject monster, ItemObject... itemList) {
this(base, monster);
items = new ArrayList<ItemObject>(itemList.length);
for (int i = 0; i < itemList.length; i++) {
items.add(itemList[i]);
}
}
public boolean hasBeenSeen(){
return flooring.isEverSeen();
}
public void setHasBeenSeen(){
setHasBeenSeen(true);
}
public void setHasBeenSeen(boolean seen){
flooring.setEverSeen(seen);
}
public boolean isChanged(){
return changed;
}
public void setChanged(boolean change){
changed = change;
}
public void setChanged(){
setChanged(true);
}
public void setFlooring(TerrainObject floor) {
flooring = floor;
}
public void setFlooring() {
flooring = new FloorObject();
}
public void setMonster(MonsterObject mon) {
monster = mon;
}
public MonsterObject getMonster() {
return monster;
}
public boolean hasMonster() {
return !(monster == null);
}
public boolean hasItem() {
if (items == null) {
return false;
}
if (items.isEmpty()) {
return false;
}
return true;
}
public boolean isFloor() {
return (flooring instanceof FloorObject);
}
public boolean isStairs() {
return (flooring instanceof StairsObject);
}
public boolean isWall() {
return (flooring instanceof WallObject);
}
public BaseObject getFlooring() {
return flooring;
}
public BaseObject getTopObject() {
if (hasMonster()) {
return monster;
} else if (hasItem()) {
return items.get(0);
}
return flooring;
}
public String getTopObjectName() {
Object obj = getTopObject();
if (obj instanceof BaseObject) {
BaseObject tempObj = (BaseObject) obj;
return tempObj.getName();
}
if (obj instanceof ItemObject) {
return "an item";
}
return "nothing";
}
public boolean isPassable() {
if (!flooring.passable) {
return false;
} else if (hasMonster()) {
if (!monster.passable) {
return false;
}
}
return true;
}
public boolean isVisible() {
if (flooring.visible == 0) {
return false;
} else if (hasMonster()) {
if (monster.visible == 0) {
return false;
}
}
return true;
}
public void setVisible(boolean vis){
if (vis){
setVisible(100);
}else{
setVisible(0);
}
}
public void setVisible(){
setVisible(100);
}
public void setVisible(double vis){
flooring.visible = vis;
if (hasMonster()){
monster.visible = vis;
}
}
public double getVisible(){
if (hasMonster()){
return Math.max(Math.max(0, monster.getVisible()), flooring.getVisible());}
else{
return Math.max(0, flooring.getVisible());
}
}
public void objectOutput(BufferedWriter writer) throws IOException {
writer.write(flooring.outputObjectToFile());
if (hasMonster()) {
writer.write(monster.outputObjectToFile());
}
if (hasItem()) {
for (int i = 0; i < items.size(); i++) {
items.get(i).outputObjectToFile();
}
}
}
public void resetMe() {
flooring = null;
monster = null;
items = null;
}
public String pushObject(BufferedReader reader, String type) throws IOException {
resetMe();
String currentType = type;
if (currentType.equalsIgnoreCase("FoldObject")) {
flooring = new FoldObject();
} else if (currentType.equalsIgnoreCase("FloorObject")) {
flooring = new FloorObject();
} else if (currentType.equalsIgnoreCase("StairsObject")) {
flooring = new StairsObject();
} else if (currentType.equalsIgnoreCase("WallObject")) {
flooring = new WallObject();
} else {
throw new IOException("Object not known.");
}
flooring.inputObjectFromFile(reader);
reader.readLine(); //gets rid of readability space between entries
currentType = reader.readLine();
if (currentType.equals("MonsterObject")) {
monster = new MonsterObject();
monster.inputObjectFromFile(reader);
reader.readLine(); //gets rid of readability space between entries
currentType = reader.readLine();
}
if (currentType.equals("ItemObject")) {
items = new ArrayList<ItemObject>();
ItemObject tempItem;
do {
tempItem = new ItemObject();
tempItem.inputObjectFromFile(reader);
items.add(tempItem);
reader.readLine(); //gets rid of readability space between entries
currentType = reader.readLine();
} while (currentType.equals("ItemObject"));
}
return currentType;
}
}