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
Raw Normal View History

package com.github.dtschust.zork;
import java.util.List;
/*Trigger*/
2022-11-16 16:18:19 +00:00
public class ZorkTrigger {
2022-11-21 21:29:36 +00:00
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;
2022-11-21 21:29:36 +00:00
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) {
2022-11-21 21:29:36 +00:00
if (!commands.stream().allMatch(c -> c.matchesInput(zork.userInput))) {
return false;
}
2022-11-21 21:29:36 +00:00
return conditions.stream().allMatch(c -> c.evaluate(zork.game));
}
}