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(); + } + } } }