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/repl/actions/TurnOnAction.java

45 lines
1.3 KiB
Java

package com.github.dtschust.zork.repl.actions;
import com.github.dtschust.zork.parser.ZorkGame;
import com.github.dtschust.zork.repl.Action;
import com.github.dtschust.zork.repl.ActionDispatcher;
import com.github.dtschust.zork.types.ZorkItem;
import java.util.List;
/**
* Turn on an item
*/
public class TurnOnAction extends Action {
@Override
public boolean matchesInput(List<String> arguments) {
return arguments.get(0).equals("turn") && arguments.get(1).equals("on");
}
@Override
public int getMinimumArgCount() {
return 3;
}
@Override
public void run(ZorkGame game, List<String> arguments) {
final String what = arguments.get(2);
if (game.inventory.contains(what)) {
ZorkItem tempItem = (ZorkItem) game.get("item", what);
System.out.println("You activate the " + what + ".");
if (tempItem != null) {
for (String print : tempItem.turnOnPrint) {
System.out.println(print);
}
final ActionDispatcher effectsDispatcher = new ActionDispatcher(game);
for (final String action : tempItem.turnOnAction) {
effectsDispatcher.dispatch(action);
}
return;
}
}
System.out.println("Error");
}
}