This repository has been archived on 2022-12-21. You can view files and clone it, but cannot push or open issues or pull requests.
sdm03/src/main/java/com/github/dtschust/zork/ZorkTrigger.java

37 lines
1.0 KiB
Java

package com.github.dtschust.zork;
import java.util.List;
/*Trigger*/
public class ZorkTrigger {
private final List<ZorkCondition> conditions;
private final List<ZorkCommand> commands;
public final List<String> print;
public final List<String> action;
/* By default, "single" */
public final String type;
public boolean hasCommand() {
return !this.commands.isEmpty();
}
public ZorkTrigger(final String type,
final List<ZorkCondition> conditions,
final List<ZorkCommand> commands,
final List<String> print,
final List<String> action) {
this.conditions = conditions;
this.commands = commands;
this.print = print;
this.action = action;
this.type = type;
}
public boolean evaluate(Zork zork) {
if (!commands.stream().allMatch(c -> c.matchesInput(zork.userInput))) {
return false;
}
return conditions.stream().allMatch(c -> c.evaluate(zork.game));
}
}