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