41 lines
1.2 KiB
Java
41 lines
1.2 KiB
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.objects.ZorkContainer;
|
|
|
|
import java.util.List;
|
|
|
|
import static com.github.dtschust.zork.objects.ZorkObjectTypes.CONTAINER;
|
|
|
|
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();
|
|
} else {
|
|
return false;
|
|
}
|
|
} else {
|
|
ZorkContainer tempContainer;
|
|
if (game.getCurrentRoom().getContainer().contains(what)) {
|
|
tempContainer = (ZorkContainer) game.get(CONTAINER, what);
|
|
tempContainer.open();
|
|
game.stream.println(tempContainer.getContents());
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
}
|