Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void moveRobot(Robot robot, int toX, int toY) {
- int currentX = robot.getX();
- int currentY = robot.getY();
- Direction currentDirection = robot.getDirection();
- if (currentX < toX){
- /** Надо двигаться вправо */
- while(currentDirection != Direction.RIGHT) {
- robot.turnRight();
- currentDirection = robot.getDirection();
- }}
- if (currentX > toX){
- /** Надо двигаться влево */
- while(currentDirection != Direction.LEFT) {
- robot.turnRight();
- currentDirection = robot.getDirection();
- }}
- int stepRightLeft = Math.abs(currentX - toX);
- for (int i = 0; i < stepRightLeft; i++){
- robot.stepForward(); }
- currentDirection = robot.getDirection();
- if (currentY < toY){
- /** Надо двигаться вверх */
- while(currentDirection != Direction.UP) {
- robot.turnRight();
- currentDirection = robot.getDirection();
- }}
- if (currentX > toX){
- /** Надо двигаться вниз */
- while(currentDirection != Direction.DOWN) {
- robot.turnRight();
- currentDirection = robot.getDirection();
- }}
- int stepUpDown = Math.abs(currentY - toY);
- for (int i = 0; i < stepUpDown; i++){
- robot.stepForward(); }
- // your implementation here
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement