43 lines
1.4 KiB
Java
43 lines
1.4 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 OpenAction extends Action {
|
|
@Override
|
|
public boolean matchesInput(List<String> arguments) {
|
|
return arguments.get(0).equals("open");
|
|
}
|
|
|
|
@Override
|
|
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");
|
|
}
|
|
} else {
|
|
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");
|
|
} else {
|
|
final String output = String.join(", ", tempContainer.item);
|
|
System.out.println(what + " contains " + output + ".");
|
|
}
|
|
} else {
|
|
System.out.println("Error");
|
|
}
|
|
}
|
|
}
|
|
}
|