60 lines
1.6 KiB
Java
60 lines
1.6 KiB
Java
package com.github.dtschust.zork.types;
|
|
|
|
import com.github.dtschust.zork.Zork;
|
|
import com.github.dtschust.zork.ZorkTrigger;
|
|
|
|
import java.util.*;
|
|
|
|
import static com.github.dtschust.zork.Zork.Type.ITEM;
|
|
|
|
/* Container*/
|
|
public class ZorkContainer extends ZorkObject implements HasSetOfCollectable {
|
|
public final Set<String> item;
|
|
private final List<String> accepts;
|
|
private boolean open;
|
|
|
|
public ZorkContainer(final String name,
|
|
final String description,
|
|
final String status,
|
|
final Collection<String> items,
|
|
final Collection<String> accepts,
|
|
final Collection<ZorkTrigger> triggers) {
|
|
super(name, description, status, triggers);
|
|
// If a container has an accepts attribute, then it is always open
|
|
this.open = !accepts.isEmpty();
|
|
this.item = new HashSet<>(items);
|
|
this.accepts = new ArrayList<>(accepts);
|
|
}
|
|
|
|
public void addItem(final String item) {
|
|
this.item.add(item);
|
|
}
|
|
|
|
public void removeItem(final String item) {
|
|
this.item.remove(item);
|
|
}
|
|
|
|
public boolean containsItem(final String item) {
|
|
return this.item.contains(item);
|
|
}
|
|
|
|
public boolean isEmpty() {
|
|
return this.item.isEmpty();
|
|
}
|
|
|
|
public boolean isOpen() {
|
|
return open;
|
|
}
|
|
|
|
public void open() {
|
|
open = true;
|
|
}
|
|
|
|
@Override
|
|
public Set<String> getSetFromType(Zork.Type type) {
|
|
if (type.equals(ITEM))
|
|
return item;
|
|
throw new IllegalStateException("Unexpected value: " + type);
|
|
}
|
|
}
|