diff --git a/src/main/java/core/basesyntax/RobotRoute.java b/src/main/java/core/basesyntax/RobotRoute.java index 351ca4b9..b4679320 100644 --- a/src/main/java/core/basesyntax/RobotRoute.java +++ b/src/main/java/core/basesyntax/RobotRoute.java @@ -2,6 +2,33 @@ public class RobotRoute { public void moveRobot(Robot robot, int toX, int toY) { - //write your solution here + + if (robot.getX() < toX) { + while (robot.getDirection() != Direction.RIGHT) { + robot.turnRight(); + } + } + if (robot.getX() > toX) { + while (robot.getDirection() != Direction.LEFT) { + robot.turnLeft(); + } + } + while (robot.getX() != toX) { + robot.stepForward(); + } + + if (robot.getY() < toY) { + while (robot.getDirection() != Direction.UP) { + robot.turnRight(); + } + } + if (robot.getY() > toY) { + while (robot.getDirection() != Direction.DOWN) { + robot.turnRight(); + } + } + while (robot.getY() != toY) { + robot.stepForward(); + } } -} +} \ No newline at end of file