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.ZorkContainer;
import java.util.List;
import static com.github.dtschust.zork.Zork.Type.CONTAINER;
public class OpenAction implements Action {
@Override
public boolean matchesInput(List<String> arguments) {
return arguments.get(0).equals("open");
}
public void run(ZorkGame game, List<String> arguments) {
final String what = arguments.get(1);
if (what.equals("exit")) {
if (game.getCurrentRoom().type.equals("exit")) {
System.out.println("Game Over");
game.setGameOver();
} else {
System.out.println("Error");
ZorkContainer tempContainer;
if (game.getCurrentRoom().container.contains(what)) {
tempContainer = (ZorkContainer) game.get(CONTAINER, what);
tempContainer.open();
if (tempContainer.item.isEmpty()) {
System.out.println(what + " is empty");
final String output = String.join(", ", tempContainer.item);
System.out.println(what + " contains " + output + ".");