37 lines
1.0 KiB
Java
37 lines
1.0 KiB
Java
package com.github.dtschust.zork.repl.actions;
|
|
|
|
import com.github.dtschust.zork.ZorkGame;
|
|
import com.github.dtschust.zork.repl.Action;
|
|
|
|
import java.util.List;
|
|
import java.util.Optional;
|
|
|
|
/**
|
|
* Turn on an item
|
|
*/
|
|
public class TurnOnAction implements 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 boolean run(ZorkGame game, List<String> arguments) {
|
|
final String what = arguments.get(2);
|
|
final boolean inInventory = game.inventory.contains(what);
|
|
|
|
return Optional.ofNullable(inInventory ? what : null)
|
|
.flatMap(game::getItem)
|
|
.map(i -> {
|
|
game.stream.println("You activate the " + i.getName() + ".");
|
|
i.printAndExecuteActions(game);
|
|
return true;
|
|
}).orElse(false);
|
|
}
|
|
}
|