From 88c4e6fff09309eababaf6d82c0b50ffecce2602 Mon Sep 17 00:00:00 2001 From: Panchenko Vlada Date: Sun, 1 Dec 2024 17:48:49 +0200 Subject: [PATCH] Create robot --- robot | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 robot diff --git a/robot b/robot new file mode 100644 index 00000000..697a5b16 --- /dev/null +++ b/robot @@ -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(); + } + } + } +}