37 lines
1.1 KiB
Java
37 lines
1.1 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.types.ZorkContainer;
|
|
|
|
import java.util.List;
|
|
|
|
public class PutAction extends Action {
|
|
@Override
|
|
public boolean matchesInput(List<String> arguments) {
|
|
return arguments.get(0).equals("put");
|
|
}
|
|
|
|
@Override
|
|
public int getMinimumArgCount() {
|
|
return 4;
|
|
}
|
|
|
|
@Override
|
|
public void run(ZorkGame game, List<String> arguments) {
|
|
final String what = arguments.get(1);
|
|
final String destination = arguments.get(3);
|
|
|
|
if (game.getCurrentRoom().container.contains(destination)) {
|
|
ZorkContainer tempContainer = (ZorkContainer) game.get("container", destination);
|
|
if (tempContainer.isOpen() && game.inventory.contains(what)) {
|
|
tempContainer.item.add(what);
|
|
game.inventory.remove(what);
|
|
System.out.println("Item " + what + " added to " + destination + ".");
|
|
return;
|
|
}
|
|
}
|
|
System.out.println("Error");
|
|
}
|
|
}
|