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/PutAction.java

32 lines
972 B
Java
Raw Normal View History

package com.github.dtschust.zork.repl.actions;
import com.github.dtschust.zork.ZorkGame;
import com.github.dtschust.zork.repl.Action;
import java.util.List;
public class PutAction implements Action {
@Override
public boolean matchesInput(List<String> arguments) {
return arguments.get(0).equals("put");
}
@Override
public int getMinimumArgCount() {
return 4;
}
@Override
2022-11-22 17:03:09 +00:00
public boolean run(ZorkGame game, List<String> arguments) {
final String what = arguments.get(1);
2022-11-22 17:31:06 +00:00
return game.getContainer(arguments.get(3))
2022-11-22 17:36:17 +00:00
.filter(c -> c.isOpen() && game.inventory.contains(what))
.map(tempContainer -> {
tempContainer.addItem(what);
game.inventory.remove(what);
game.stream.println("Item " + what + " added to " + tempContainer.getName() + ".");
return true;
}).orElse(false);
}
}