added turtle program

This commit is contained in:
Djeeberjr 2023-04-14 14:36:09 +02:00
parent f9aadbcbe9
commit 17be4149db
2 changed files with 46 additions and 0 deletions

View File

@ -153,6 +153,8 @@ class Terminal extends UIApp {
return new Disk(); return new Disk();
case "gps": case "gps":
return new GPS(); return new GPS();
case "turtle":
return new Turtle();
default: default:
return null; return null;
} }

44
src/bin/Turtle.hx Normal file
View File

@ -0,0 +1,44 @@
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;
}
}
}