76 lines
2.2 KiB
Java
76 lines
2.2 KiB
Java
package com.github.dtschust.zork.types;
|
|
|
|
|
|
import com.github.dtschust.zork.Zork;
|
|
import com.github.dtschust.zork.ZorkTrigger;
|
|
|
|
import java.util.*;
|
|
|
|
/* Room*/
|
|
public class ZorkRoom extends ZorkObject implements HasSetOfCollectable {
|
|
private final String type;
|
|
private final Map<ZorkDirection, String> border;
|
|
private final Set<String> container;
|
|
private final Set<String> item;
|
|
private final Set<String> creature;
|
|
|
|
public ZorkRoom(final String name,
|
|
final String description,
|
|
final String type,
|
|
final String status,
|
|
final Collection<ZorkTrigger> triggers,
|
|
final Map<ZorkDirection, String> borders,
|
|
final Collection<String> containers,
|
|
final Collection<String> items,
|
|
final Collection<String> creatures) {
|
|
super(name, description, status, triggers);
|
|
this.type = type;
|
|
this.border = new HashMap<>(borders);
|
|
this.container = new HashSet<>(containers);
|
|
this.item = new HashSet<>(items);
|
|
this.creature = new HashSet<>(creatures);
|
|
}
|
|
|
|
@Override
|
|
public Set<String> getSetFromType(Zork.Type type) {
|
|
switch (type) {
|
|
case CONTAINER:
|
|
return getContainer();
|
|
case CREATURE:
|
|
return getCreature();
|
|
case ITEM:
|
|
return getItem();
|
|
default:
|
|
throw new IllegalStateException("Unexpected value: " + type);
|
|
}
|
|
}
|
|
|
|
public boolean isExit() {
|
|
return "exit".equals(type);
|
|
}
|
|
|
|
public void removeBorderingRoom(String roomName) {
|
|
for (final ZorkDirection d : this.border.keySet()) {
|
|
if (this.border.get(d).equals(roomName)) {
|
|
this.border.remove(d);
|
|
}
|
|
}
|
|
}
|
|
|
|
public Optional<String> getBorderingRoom(ZorkDirection border) {
|
|
return Optional.ofNullable(this.border.get(border));
|
|
}
|
|
|
|
public Set<String> getContainer() {
|
|
return container;
|
|
}
|
|
|
|
public Set<String> getItem() {
|
|
return item;
|
|
}
|
|
|
|
public Set<String> getCreature() {
|
|
return creature;
|
|
}
|
|
}
|