Advertisement
Guest User

Untitled

a guest
Dec 17th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. public static void moveRobot(Robot robot, int toX, int toY) {
  2. int currentX = robot.getX();
  3. int currentY = robot.getY();
  4. Direction currentDirection = robot.getDirection();
  5. if (currentX < toX){
  6. /** Надо двигаться вправо */
  7. while(currentDirection != Direction.RIGHT) {
  8. robot.turnRight();
  9. currentDirection = robot.getDirection();
  10. }}
  11. if (currentX > toX){
  12. /** Надо двигаться влево */
  13. while(currentDirection != Direction.LEFT) {
  14. robot.turnRight();
  15. currentDirection = robot.getDirection();
  16. }}
  17. int stepRightLeft = Math.abs(currentX - toX);
  18. for (int i = 0; i < stepRightLeft; i++){
  19. robot.stepForward(); }
  20. currentDirection = robot.getDirection();
  21. if (currentY < toY){
  22. /** Надо двигаться вверх */
  23. while(currentDirection != Direction.UP) {
  24. robot.turnRight();
  25. currentDirection = robot.getDirection();
  26. }}
  27. if (currentX > toX){
  28. /** Надо двигаться вниз */
  29. while(currentDirection != Direction.DOWN) {
  30. robot.turnRight();
  31. currentDirection = robot.getDirection();
  32. }}
  33. int stepUpDown = Math.abs(currentY - toY);
  34. for (int i = 0; i < stepUpDown; i++){
  35. robot.stepForward(); }
  36.  
  37. // your implementation here
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement