37 lines
982 B
Java
37 lines
982 B
Java
package com.github.dtschust.zork.repl.actions;
|
|
|
|
import com.github.dtschust.zork.ZorkGame;
|
|
import com.github.dtschust.zork.repl.Action;
|
|
import com.github.dtschust.zork.types.ZorkRoom;
|
|
|
|
import java.util.List;
|
|
|
|
import static com.github.dtschust.zork.Zork.Type.ROOM;
|
|
|
|
public class DropItemAction implements Action {
|
|
@Override
|
|
public boolean matchesInput(List<String> arguments) {
|
|
return arguments.get(0).equals("drop");
|
|
}
|
|
|
|
@Override
|
|
public int getMinimumArgCount() {
|
|
return 2;
|
|
}
|
|
|
|
@Override
|
|
public void run(ZorkGame game, List<String> arguments) {
|
|
final String what = arguments.get(1);
|
|
|
|
if (game.inventory.contains(what)) {
|
|
ZorkRoom tempRoom = game.getCurrentRoom();
|
|
tempRoom.item.add(what);
|
|
game.put(ROOM, tempRoom);
|
|
game.inventory.remove(what);
|
|
System.out.println(what + " dropped.");
|
|
} else {
|
|
System.out.println("Error");
|
|
}
|
|
}
|
|
}
|