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

35 lines
958 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 OpenAction implements Action {
@Override
public boolean matchesInput(List<String> arguments) {
return arguments.get(0).equals("open");
}
@Override
public boolean run(ZorkGame game, List<String> arguments) {
final String what = arguments.get(1);
if (what.equals("exit")) {
if (game.getCurrentRoom().isExit()) {
game.stream.println("Game Over");
game.setGameOver();
return true;
} else {
return false;
}
} else {
return game.getContainer(what).map(cont -> {
cont.open();
game.stream.println(cont.getContents());
return true;
}).orElse(false);
}
}
}