From 16affffbfa2c5969b0a501f2c51cfad10fd24024 Mon Sep 17 00:00:00 2001 From: clo3eX Date: Sun, 8 Sep 2024 16:31:17 +0200 Subject: [PATCH] Added solution --- src/main/java/core/basesyntax/RobotRoute.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/main/java/core/basesyntax/RobotRoute.java b/src/main/java/core/basesyntax/RobotRoute.java index 351ca4b9..d3d93d25 100644 --- a/src/main/java/core/basesyntax/RobotRoute.java +++ b/src/main/java/core/basesyntax/RobotRoute.java @@ -2,6 +2,26 @@ public class RobotRoute { public void moveRobot(Robot robot, int toX, int toY) { - //write your solution here + while (toX != robot.getX() || toY != robot.getY()) { + if (toX > robot.getX()) { + while (robot.getDirection() != Direction.RIGHT) { + robot.turnRight(); + } + } else if (toX < robot.getX()) { + while (robot.getDirection() != Direction.LEFT) { + robot.turnLeft(); + } + } + if (toY > robot.getY()) { + while (robot.getDirection() != Direction.UP) { + robot.turnRight(); + } + } else if (toY < robot.getY()) { + while (robot.getDirection() != Direction.DOWN) { + robot.turnLeft(); + } + } + robot.stepForward(); + } } }