Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Mazes
- {
- public static class DiagonalMazeTask
- {
- public static void MoveDown(Robot robot, int yMoves)
- {
- for (int i = 0; i < yMoves; i++) robot.MoveTo(Direction.Down);
- }
- public static void MoveRight(Robot robot, int xMoves)
- {
- for (int i = 0; i < xMoves; i++) robot.MoveTo(Direction.Right);
- }
- public static void MoveOut(Robot robot, int width, int height)
- {
- int yMoves = 0;
- int xMoves = 0;
- int repeats = 0;
- ActionsCounter(height, width, ref xMoves, ref yMoves, ref repeats);
- Move(xMoves, yMoves, repeats, height, width, robot);
- }
- public static void ActionsCounter(int height, int width, ref int xMoves, ref int yMoves, ref int repeats)
- {
- if (height > width)
- {
- xMoves = 1;
- yMoves = (height - 3) / (width - 2);
- repeats = (height - 3) / yMoves;
- }
- else
- {
- xMoves = (width - 3) / (height - 2);
- yMoves = 1;
- repeats = (width - 3) / xMoves;
- }
- }
- public static void Move(int xMoves, int yMoves, int repeats, int height, int width, Robot robot)
- {
- for (int i = 0; i < repeats; i++)
- {
- if (height > width)
- {
- MoveDown(robot, yMoves);
- if (i + 1 != repeats) MoveRight(robot, xMoves);
- }
- else
- {
- MoveRight(robot, xMoves);
- if (i + 1 != repeats) MoveDown(robot, yMoves);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment