Skip to content

Commit

Permalink
Create robot
Browse files Browse the repository at this point in the history
  • Loading branch information
PVladster authored Dec 1, 2024
1 parent 80be487 commit 88c4e6f
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
public class RobotRoute {
public void moveRobot(Robot robot, int toX, int toY) {
if (toX < robot.getX()) {
while (robot.getDirection() != Direction.LEFT) {
robot.turnLeft();
}
while (toX != robot.getX()) {
robot.stepForward();
}

} else {
while (robot.getDirection() != Direction.RIGHT) {
robot.turnRight();
}
while (toX != robot.getX()) {
robot.stepForward();
}
}

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

} else {
while (robot.getDirection() != Direction.UP) {
robot.turnRight();
}
while (toY != robot.getY()) {
robot.stepForward();
}
}
}
}

0 comments on commit 88c4e6f

Please sign in to comment.