style: Add turnLeft and turnRight methods to Turtle class for directional control
This commit is contained in:
@@ -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.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user