42 lines
1.3 KiB
Java
42 lines
1.3 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.HasSetOfCollectable;
|
|
import com.github.dtschust.zork.types.ZorkGameStatusType;
|
|
import com.github.dtschust.zork.types.ZorkObject;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
* Add: figure out what type the destination is, then what type the object is. Then add object to destination if it makes sense
|
|
*/
|
|
public class AddAction implements Action {
|
|
@Override
|
|
public boolean matchesInput(List<String> arguments) {
|
|
return arguments.get(0).equals("Add");
|
|
}
|
|
|
|
@Override
|
|
public int getMinimumArgCount() {
|
|
return 4;
|
|
}
|
|
|
|
@Override
|
|
public void run(ZorkGame game, List<String> arguments) {
|
|
final String object = arguments.get(1);
|
|
final String destination = arguments.get(3);
|
|
|
|
try {
|
|
ZorkGameStatusType destType = game.getTypeFromLookup(destination);
|
|
ZorkGameStatusType objType = game.getTypeFromLookup(object);
|
|
ZorkObject tempObject = game.get(destType, destination);
|
|
((HasSetOfCollectable) tempObject).getSetFromType(objType).add(object);
|
|
game.put(destType, tempObject);
|
|
} catch (Exception e) {
|
|
System.out.println("Error");
|
|
}
|
|
}
|
|
}
|