45 lines
974 B
Haxe
45 lines
974 B
Haxe
package bin;
|
|
|
|
import lib.CLIAppBase;
|
|
|
|
using tink.CoreApi;
|
|
|
|
class Turtle extends CLIAppBase {
|
|
public function new() {
|
|
registerSyncSubcommand("forward", (args)->{
|
|
return perform(kernel.turtle.Turtle.instance.forward());
|
|
});
|
|
|
|
registerSyncSubcommand("back", (args)->{
|
|
return perform(kernel.turtle.Turtle.instance.back());
|
|
});
|
|
|
|
registerSyncSubcommand("left", (args)->{
|
|
return perform(kernel.turtle.Turtle.instance.turnLeft());
|
|
});
|
|
|
|
registerSyncSubcommand("right", (args)->{
|
|
return perform(kernel.turtle.Turtle.instance.turnRight());
|
|
});
|
|
|
|
registerSyncSubcommand("up", (args)->{
|
|
return perform(kernel.turtle.Turtle.instance.up());
|
|
});
|
|
|
|
registerSyncSubcommand("down", (args)->{
|
|
return perform(kernel.turtle.Turtle.instance.down());
|
|
});
|
|
}
|
|
|
|
private function perform(outcome: Outcome<Noise,String>): Bool {
|
|
switch outcome {
|
|
case Success(_):
|
|
return true;
|
|
case Failure(error):
|
|
handle.write(error);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
}
|