From 28de0c57d9701ef7d1daa98f40d3206ed6c8e3d4 Mon Sep 17 00:00:00 2001 From: xMax Date: Wed, 1 Jan 2025 12:31:11 +0100 Subject: [PATCH] solved --- src/main/java/core/basesyntax/RobotRoute.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/main/java/core/basesyntax/RobotRoute.java b/src/main/java/core/basesyntax/RobotRoute.java index 351ca4b9..9e143cc5 100644 --- a/src/main/java/core/basesyntax/RobotRoute.java +++ b/src/main/java/core/basesyntax/RobotRoute.java @@ -2,6 +2,25 @@ public class RobotRoute { public void moveRobot(Robot robot, int toX, int toY) { - //write your solution here + while (robot.getX() != toX || robot.getY() != toY) { + while (robot.getX() < toX && robot.getDirection() != Direction.RIGHT) { + robot.turnRight(); + } + while (robot.getX() > toX && robot.getDirection() != Direction.LEFT) { + robot.turnLeft(); + } + while (robot.getX() != toX) { + robot.stepForward(); + } + while (robot.getY() > toY && robot.getDirection() != Direction.DOWN) { + robot.turnLeft(); + } + while (robot.getY() < toY && robot.getDirection() != Direction.UP) { + robot.turnRight(); + } + while (robot.getY() != toY) { + robot.stepForward(); + } + } } }