32 lines
972 B
Java
32 lines
972 B
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;
|
|
|
|
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
|
|
public boolean run(ZorkGame game, List<String> arguments) {
|
|
final String what = arguments.get(1);
|
|
return game.getContainer(arguments.get(3))
|
|
.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);
|
|
}
|
|
}
|