diff --git a/src/main/java/core/basesyntax/RobotRoute.java b/src/main/java/core/basesyntax/RobotRoute.java index 351ca4b9..863ffa74 100644 --- a/src/main/java/core/basesyntax/RobotRoute.java +++ b/src/main/java/core/basesyntax/RobotRoute.java @@ -2,6 +2,30 @@ public class RobotRoute { public void moveRobot(Robot robot, int toX, int toY) { - //write your solution here + int currentX = robot.getX(); + int currentY = robot.getY(); + if (currentX < toX) { + while (robot.getDirection() != Direction.RIGHT) { + robot.turnRight(); + } + } + else if (currentX > toX) { + while (robot.getDirection() != Direction.LEFT) { + robot.turnLeft(); + } + } + else if (currentY < toY) { + while (robot.getDirection() != Direction.UP) { + robot.turnLeft(); + } + } + else if (currentY > toY) { + while (robot.getDirection() != Direction.DOWN) { + robot.turnLeft(); + } + } + while (currentX != toX || currentY != toY) { + robot.stepForward(); + } } }