From 586b161da946e8d37f8a4e0dc28dd3b56bb4b020 Mon Sep 17 00:00:00 2001 From: MayaTheShy Date: Fri, 20 Feb 2026 03:41:46 -0500 Subject: [PATCH] style: Add turnLeft and turnRight methods to Turtle class for directional control --- server/Turtle.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/server/Turtle.js b/server/Turtle.js index 1f9a3bd..06f40dc 100644 --- a/server/Turtle.js +++ b/server/Turtle.js @@ -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. */