From 117ce02408bd45b85f618751b7e3396a251b2b52 Mon Sep 17 00:00:00 2001 From: Stanislav Hohulia Date: Thu, 14 Mar 2024 10:53:42 +0200 Subject: [PATCH] Create task solution --- src/main/java/core/basesyntax/RobotRoute.java | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/main/java/core/basesyntax/RobotRoute.java b/src/main/java/core/basesyntax/RobotRoute.java index 351ca4b9..5cffa1d3 100644 --- a/src/main/java/core/basesyntax/RobotRoute.java +++ b/src/main/java/core/basesyntax/RobotRoute.java @@ -2,6 +2,37 @@ public class RobotRoute { public void moveRobot(Robot robot, int toX, int toY) { - //write your solution here + if (toX > robot.getX()) { + while (robot.getDirection() != Direction.RIGHT) { + robot.turnRight(); + } + for (; robot.getX() < toX; robot.stepForward()) { + + } + } else { + while (robot.getDirection() != Direction.LEFT) { + robot.turnRight(); + } + for (; robot.getX() > toX; robot.stepForward()) { + + } + } + if (toY > robot.getY()) { + while (robot.getDirection() != Direction.UP) { + robot.turnRight(); + } + for (; robot.getY() < toY; robot.stepForward()) { + + } + + } else { + while (robot.getDirection() != Direction.DOWN) { + robot.turnRight(); + } + + for (; robot.getY() > toY; robot.stepForward()) { + + } + } } }