pevel

Untitled

Sep 28th, 2022
797
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.78 KB | Source Code | 0 0
  1. namespace Mazes
  2. {
  3.     public static class SnakeMazeTask
  4.     {
  5.         private static Robot _robot;
  6.         private static int _width;
  7.         private static int _height;
  8.        
  9.         public static void MoveOut(Robot robot, int width, int height)
  10.         {
  11.             _robot = robot;
  12.             _width = width;
  13.             _height = height;
  14.             MoveSnake();
  15.         }
  16.  
  17.         private static void MoveSnake()
  18.         {
  19.             while (true)
  20.             {
  21.                 MoveToManySteps(Direction.Right, _width - 3);
  22.                 MoveToManySteps(Direction.Down, 2);
  23.                 MoveToManySteps(Direction.Left, _width - 3);
  24.                 if (_robot.X == 1 && _robot.Y == _height - 2)
  25.                     break;
  26.                 MoveToManySteps(Direction.Down, 2);
  27.             }
  28.         }
  29.         private static void MoveToManySteps(Direction direction, int countSteps)
  30.         {
  31.             for (var i = 0; i < countSteps; i++)
  32.                 _robot.MoveTo(direction);
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment