From f4e428f065e6c535045c1277ade001dddb9d86c0 Mon Sep 17 00:00:00 2001 From: Danil Date: Thu, 7 Nov 2024 19:15:20 +0100 Subject: [PATCH 1/3] Changed RobotRoute.java --- src/main/java/core/basesyntax/RobotRoute.java | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/main/java/core/basesyntax/RobotRoute.java b/src/main/java/core/basesyntax/RobotRoute.java index 351ca4b9..655c0471 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 + //write your solution here + if (robot.getX() < toX) { + robot.turnRight(); + while (robot.getX() < toX) { + robot.stepForward(); + } + robot.turnLeft(); + } else if (robot.getX() > toX) { + robot.turnLeft(); + while (robot.getX() > toX) { + robot.stepForward(); + } + robot.turnRight(); + } + + if (robot.getY() < toY) { + while (robot.getY() < toY) { + robot.stepForward(); + } + } else if (robot.getY() > toY) { + robot.turnRight(); + robot.turnRight(); + while (robot.getY() > toY) { + robot.stepForward(); + } + robot.turnLeft(); + robot.turnLeft(); + } } } From 62788afba9903f6b51db206ab197ab56f5ef7c37 Mon Sep 17 00:00:00 2001 From: Danil Date: Thu, 7 Nov 2024 19:26:15 +0100 Subject: [PATCH 2/3] Changed RobotRoute.java --- src/main/java/core/basesyntax/RobotRoute.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/main/java/core/basesyntax/RobotRoute.java b/src/main/java/core/basesyntax/RobotRoute.java index 655c0471..25149ef2 100644 --- a/src/main/java/core/basesyntax/RobotRoute.java +++ b/src/main/java/core/basesyntax/RobotRoute.java @@ -4,31 +4,33 @@ public class RobotRoute { public void moveRobot(Robot robot, int toX, int toY) { //write your solution here if (robot.getX() < toX) { - robot.turnRight(); + faceDirection(robot, Direction.RIGHT); while (robot.getX() < toX) { robot.stepForward(); } - robot.turnLeft(); } else if (robot.getX() > toX) { - robot.turnLeft(); + faceDirection(robot, Direction.LEFT); while (robot.getX() > toX) { robot.stepForward(); } - robot.turnRight(); } if (robot.getY() < toY) { + faceDirection(robot, Direction.UP); while (robot.getY() < toY) { robot.stepForward(); } } else if (robot.getY() > toY) { - robot.turnRight(); - robot.turnRight(); + faceDirection(robot, Direction.DOWN); while (robot.getY() > toY) { robot.stepForward(); } - robot.turnLeft(); - robot.turnLeft(); + } + } + + private void faceDirection(Robot robot, Direction targetDirection) { + while (robot.getDirection() != targetDirection) { + robot.turnRight(); } } } From 1e3c454355a44a8105a41f6cf9dbd4d73c7c784a Mon Sep 17 00:00:00 2001 From: Danil <118832521+Danila2006@users.noreply.github.com> Date: Thu, 7 Nov 2024 19:45:03 +0100 Subject: [PATCH 3/3] Delete src/main/java/core/basesyntax/RobotRoute.java --- src/main/java/core/basesyntax/RobotRoute.java | 36 ------------------- 1 file changed, 36 deletions(-) delete mode 100644 src/main/java/core/basesyntax/RobotRoute.java diff --git a/src/main/java/core/basesyntax/RobotRoute.java b/src/main/java/core/basesyntax/RobotRoute.java deleted file mode 100644 index 25149ef2..00000000 --- a/src/main/java/core/basesyntax/RobotRoute.java +++ /dev/null @@ -1,36 +0,0 @@ -package core.basesyntax; - -public class RobotRoute { - public void moveRobot(Robot robot, int toX, int toY) { - //write your solution here - if (robot.getX() < toX) { - faceDirection(robot, Direction.RIGHT); - while (robot.getX() < toX) { - robot.stepForward(); - } - } else if (robot.getX() > toX) { - faceDirection(robot, Direction.LEFT); - while (robot.getX() > toX) { - robot.stepForward(); - } - } - - if (robot.getY() < toY) { - faceDirection(robot, Direction.UP); - while (robot.getY() < toY) { - robot.stepForward(); - } - } else if (robot.getY() > toY) { - faceDirection(robot, Direction.DOWN); - while (robot.getY() > toY) { - robot.stepForward(); - } - } - } - - private void faceDirection(Robot robot, Direction targetDirection) { - while (robot.getDirection() != targetDirection) { - robot.turnRight(); - } - } -}