36 lines
946 B
Java
36 lines
946 B
Java
package com.github.dtschust.zork.repl.actions;
|
|
|
|
import com.github.dtschust.zork.ZorkGame;
|
|
import com.github.dtschust.zork.objects.ZorkRoom;
|
|
import com.github.dtschust.zork.repl.Action;
|
|
|
|
import java.util.List;
|
|
|
|
/**
|
|
* Delete: figure out what object it is and delete it accordingly. Rooms are especially tricky
|
|
*/
|
|
public class DeleteAction implements Action {
|
|
|
|
@Override
|
|
public boolean matchesInput(List<String> arguments) {
|
|
return arguments.get(0).equals("Delete");
|
|
}
|
|
|
|
@Override
|
|
public int getMinimumArgCount() {
|
|
return 2;
|
|
}
|
|
|
|
@Override
|
|
public boolean run(ZorkGame game, List<String> arguments) {
|
|
return game.getObject(arguments.get(1)).map(o -> {
|
|
if (o instanceof ZorkRoom) {
|
|
game.removeFromBorders((ZorkRoom) o);
|
|
} else {
|
|
game.removeObjectFromCollections(o);
|
|
}
|
|
return true;
|
|
}).orElse(false);
|
|
}
|
|
}
|