Cawa245

s

Oct 5th, 2018
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. namespace Mazes
  2. {
  3. public static class DiagonalMazeTask
  4. {
  5. public static void MoveDown(Robot robot, int yMoves)
  6. {
  7. for (int i = 0; i < yMoves; i++) robot.MoveTo(Direction.Down);
  8. }
  9. public static void MoveRight(Robot robot, int xMoves)
  10. {
  11. for (int i = 0; i < xMoves; i++) robot.MoveTo(Direction.Right);
  12. }
  13. public static void MoveOut(Robot robot, int width, int height)
  14. {
  15. int yMoves = 0;
  16. int xMoves = 0;
  17. int repeats = 0;
  18. ActionsCounter(height, width, ref xMoves, ref yMoves, ref repeats);
  19. Move(xMoves, yMoves, repeats, height, width, robot);
  20. }
  21. public static void ActionsCounter(int height, int width, ref int xMoves, ref int yMoves, ref int repeats)
  22. {
  23. if (height > width)
  24. {
  25. xMoves = 1;
  26. yMoves = (height - 3) / (width - 2);
  27. repeats = (height - 3) / yMoves;
  28. }
  29. else
  30. {
  31. xMoves = (width - 3) / (height - 2);
  32. yMoves = 1;
  33. repeats = (width - 3) / xMoves;
  34. }
  35. }
  36. public static void Move(int xMoves, int yMoves, int repeats, int height, int width, Robot robot)
  37. {
  38. for (int i = 0; i < repeats; i++)
  39. {
  40. if (height > width)
  41. {
  42. MoveDown(robot, yMoves);
  43. if (i + 1 != repeats) MoveRight(robot, xMoves);
  44. }
  45. else
  46. {
  47. MoveRight(robot, xMoves);
  48. if (i + 1 != repeats) MoveDown(robot, yMoves);
  49. }
  50. }
  51. }
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment