Skip to content

Commit

Permalink
robot route movements were implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
VitaliyJvM committed Nov 2, 2024
1 parent 80be487 commit 6be4f38
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/main/java/core/basesyntax/RobotRoute.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

public class RobotRoute {
public void moveRobot(Robot robot, int toX, int toY) {
//write your solution here
Direction direction = (robot.getX() < toX) ? Direction.RIGHT : Direction.LEFT;
while (robot.getDirection() != direction) {
robot.turnRight();
}
while (robot.getX() != toX) {
robot.stepForward();
}
direction = (robot.getY() < toY) ? Direction.UP : Direction.DOWN;
while (robot.getDirection() != direction) {
robot.turnRight();
}
while (robot.getY() != toY) {
robot.stepForward();
}
}
}

0 comments on commit 6be4f38

Please sign in to comment.