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