38 lines
1.0 KiB
Java
38 lines
1.0 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.types.ZorkItem;
|
|
|
|
import java.util.List;
|
|
|
|
import static com.github.dtschust.zork.Zork.Type.ITEM;
|
|
|
|
public class ReadAction implements Action {
|
|
@Override
|
|
public boolean matchesInput(List<String> arguments) {
|
|
return arguments.get(0).equals("read");
|
|
}
|
|
|
|
@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)) {
|
|
ZorkItem tempItem = (ZorkItem) game.get(ITEM, what);
|
|
if (tempItem.writing != null && !tempItem.writing.isEmpty()) {
|
|
System.out.println(tempItem.writing);
|
|
} else {
|
|
System.out.println("Nothing written.");
|
|
}
|
|
} else {
|
|
System.out.println("Error");
|
|
}
|
|
}
|
|
}
|