Skip to content

Commit

Permalink
hw-jv-robot
Browse files Browse the repository at this point in the history
  • Loading branch information
ihor-sydorenko committed Jun 10, 2024
1 parent 80be487 commit 7d087ba
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 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,28 @@

public class RobotRoute {
public void moveRobot(Robot robot, int toX, int toY) {
//write your solution here
Direction rightDirection;
if (toX > robot.getX()) {
rightDirection = Direction.RIGHT;
} else {
rightDirection = Direction.LEFT;
}
while (robot.getDirection() != rightDirection) {
robot.turnRight();
}
while (robot.getX() != toX) {
robot.stepForward();
}
if (toY > robot.getY()) {
rightDirection = Direction.UP;
} else {
rightDirection = Direction.DOWN;
}
while (robot.getDirection() != rightDirection) {
robot.turnLeft();
}
while (robot.getY() != toY) {
robot.stepForward();
}
}
}

0 comments on commit 7d087ba

Please sign in to comment.