59 lines
1.6 KiB
Java
59 lines
1.6 KiB
Java
package com.github.dtschust.zork.objects;
|
|
|
|
import com.github.dtschust.zork.ZorkGame;
|
|
import com.github.dtschust.zork.ZorkTrigger;
|
|
import com.github.dtschust.zork.ZorkTriggerType;
|
|
|
|
import java.util.*;
|
|
|
|
/* Generic object, everything inherits from this*/
|
|
public abstract class ZorkObject {
|
|
private final String name;
|
|
private final String description;
|
|
private final List<ZorkTrigger> trigger;
|
|
private String status;
|
|
|
|
protected ZorkObject(final String name,
|
|
final String description,
|
|
final String status,
|
|
final Collection<ZorkTrigger> triggers) {
|
|
this.name = name;
|
|
this.description = description;
|
|
this.status = status;
|
|
this.trigger = new ArrayList<>(triggers);
|
|
}
|
|
|
|
|
|
public void updateStatus(String status) {
|
|
this.status = status;
|
|
}
|
|
|
|
public boolean isStatusEqualTo(String status) {
|
|
return this.status.equals(status);
|
|
}
|
|
|
|
public String getName() {
|
|
return name;
|
|
}
|
|
|
|
public String getDescription() {
|
|
return description;
|
|
}
|
|
|
|
public boolean evaluateTriggers(final ZorkGame game, final String input) {
|
|
boolean skip = false;
|
|
final Iterator<ZorkTrigger> iterator = trigger.iterator();
|
|
while (iterator.hasNext()) {
|
|
final ZorkTrigger t = iterator.next();
|
|
if (t.isTriggered(game, input)) {
|
|
t.printAndExecuteActions(game);
|
|
skip = skip || t.hasCommand();
|
|
if (t.getType() == ZorkTriggerType.SINGLE) {
|
|
iterator.remove();
|
|
}
|
|
}
|
|
}
|
|
return skip;
|
|
}
|
|
}
|