From fa79adde73e41f8170248706b4ba8eff493d6566 Mon Sep 17 00:00:00 2001 From: Illia Kulyk Date: Tue, 3 Sep 2024 19:50:32 +0300 Subject: [PATCH 1/3] new robot --- src/main/java/core/basesyntax/RobotRoute.java | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/main/java/core/basesyntax/RobotRoute.java b/src/main/java/core/basesyntax/RobotRoute.java index 351ca4b9..e1951652 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 + if (robot.getX() < toX) { + while (robot.getDirection() != Direction.RIGHT) { + robot.turnRight(); + } + } else 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(); + } + } else if (robot.getY() > toY) { + while (robot.getDirection() != Direction.DOWN){ + robot.turnRight(); + } + } + while (robot.getY() != toY) { + robot.stepForward(); + } } } From d4fe96fd34240cb774586d551725311088c3efdb Mon Sep 17 00:00:00 2001 From: Illia Kulyk Date: Tue, 3 Sep 2024 20:00:17 +0300 Subject: [PATCH 2/3] new git init --- src/main/java/core/basesyntax/RobotRoute.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/core/basesyntax/RobotRoute.java b/src/main/java/core/basesyntax/RobotRoute.java index e1951652..b64ce3a9 100644 --- a/src/main/java/core/basesyntax/RobotRoute.java +++ b/src/main/java/core/basesyntax/RobotRoute.java @@ -11,11 +11,11 @@ public void moveRobot(Robot robot, int toX, int toY) { robot.turnLeft(); } } - while (robot.getX() != toX){ + while (robot.getX() != toX) { robot.stepForward(); } - if(robot.getY() < toY) { + if (robot.getY() < toY) { while (robot.getDirection() != Direction.UP){ robot.turnRight(); } From 666be16668a4bfdbf1622b09e8888155f716ede0 Mon Sep 17 00:00:00 2001 From: Illia Kulyk Date: Tue, 3 Sep 2024 20:14:03 +0300 Subject: [PATCH 3/3] new setting s --- src/main/java/core/basesyntax/RobotRoute.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/core/basesyntax/RobotRoute.java b/src/main/java/core/basesyntax/RobotRoute.java index b64ce3a9..8f1ffb83 100644 --- a/src/main/java/core/basesyntax/RobotRoute.java +++ b/src/main/java/core/basesyntax/RobotRoute.java @@ -16,11 +16,11 @@ public void moveRobot(Robot robot, int toX, int toY) { } if (robot.getY() < toY) { - while (robot.getDirection() != Direction.UP){ + while (robot.getDirection() != Direction.UP) { robot.turnRight(); } } else if (robot.getY() > toY) { - while (robot.getDirection() != Direction.DOWN){ + while (robot.getDirection() != Direction.DOWN) { robot.turnRight(); } }