Skip to content

Commit

Permalink
maybe this time
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtemHurievskyi committed Mar 12, 2024
1 parent 7cdac69 commit 4fd9f9a
Showing 1 changed file with 20 additions and 54 deletions.
74 changes: 20 additions & 54 deletions src/main/java/core/basesyntax/RobotRoute.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,67 +2,33 @@

public class RobotRoute {
public void moveRobot(Robot robot, int toX, int toY) {
if (robot.getX() < toX) {
if (robot.getDirection() == Direction.DOWN) {
robot.turnRight();
}
if (robot.getDirection() == Direction.LEFT) {
robot.turnRight();
}
if (robot.getDirection() == Direction.RIGHT) {
robot.turnLeft();
}
while (robot.getX() != toX) {
int currentX = robot.getX();
int currentY = robot.getY();

while (robot.getX() != toX || robot.getY() != toY) {
if (currentX > toX) {
while (robot.getDirection() != Direction.UP) {
robot.turnRight();
}
robot.stepForward();
}

}

if (robot.getX() > toX) {
if (robot.getDirection() == Direction.UP) {
robot.turnRight();
}
if (robot.getDirection() == Direction.LEFT) {
robot.turnLeft();
}
if (robot.getDirection() == Direction.RIGHT) {
robot.turnRight();
}
while (robot.getX() != toX) {
} else if (currentX < toX) {
while (robot.getDirection() != Direction.DOWN) {
robot.turnRight();
}
robot.stepForward();
}

}

if (robot.getY() > toY) {
if (robot.getDirection() == Direction.UP) {
robot.turnLeft();
}

if (robot.getDirection() == Direction.RIGHT) {
robot.turnLeft();
}

while (robot.getY() != toY) {
if (currentY > toY) {
while (robot.getDirection() != Direction.LEFT) {
robot.turnRight();
}
robot.stepForward();
}

}

if (robot.getY() < toY) {
if (robot.getDirection() == Direction.DOWN) {
robot.turnLeft();
}

if (robot.getDirection() == Direction.UP) {
robot.turnRight();
}

while (robot.getY() != toY) {
} else if (currentY < toY) {
while (robot.getDirection() != Direction.RIGHT) {
robot.turnRight();
}
robot.stepForward();
}

}

}
}

0 comments on commit 4fd9f9a

Please sign in to comment.