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