style: Add turnLeft and turnRight methods to Turtle class for directional control

This commit is contained in:
MayaTheShy
2026-02-20 03:41:46 -05:00
parent 2316e14b9c
commit 586b161da9

View File

@@ -400,6 +400,30 @@ export class Turtle extends EventEmitter {
}
}
/**
* Turn the turtle left
*/
async turnLeft() {
const result = await this.exec('return turtle.turnLeft()');
if (result === true || (Array.isArray(result) && result[0] === true)) {
this._facing = (this._facing + 3) % 4;
this._emitUpdate();
}
return result;
}
/**
* Turn the turtle right
*/
async turnRight() {
const result = await this.exec('return turtle.turnRight()');
if (result === true || (Array.isArray(result) && result[0] === true)) {
this._facing = (this._facing + 1) % 4;
this._emitUpdate();
}
return result;
}
/**
* Move the turtle forward. Updates position and deletes block at destination.
*/