Ejemplo n.º 1
0
        /// <summary>
        /// Create plateau
        /// </summary>
        /// <returns></returns>
        public static Plateau initPlateau()
        {
            Plateau mars = new Plateau();

            CommonOperations.WriteConsole("Plateau created. -> " + mars.id + "-" + mars.name, ConsoleWriteType.N);

            mars.size = SetSize();

            CommonOperations.WriteConsole(mars.name + " size is: " + mars.size, ConsoleWriteType.N);
            CommonOperations.WriteConsole("---------------------------", ConsoleWriteType.N);
            return(mars);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Show created plateau size
 /// </summary>
 /// <param name="size">Plateau Size</param>
 public static void ShowPlateau(Point size)
 {
     CommonOperations.WriteConsole("Plateau looks like the following:", ConsoleWriteType.N);
     for (int i = 0; i < size.Y; i++)
     {
         for (int k = 0; k < size.X; k++)
         {
             CommonOperations.WriteConsole("* ", ConsoleWriteType.I);
         }
         CommonOperations.WriteConsole("", ConsoleWriteType.N);
     }
     CommonOperations.WriteConsole("", ConsoleWriteType.N);
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Show created rovers
        /// </summary>
        /// <param name="rovers">Created Rovers</param>
        public static void ShowRoverDetail(Rover[] rovers)
        {
            string validationMsg;

            for (int i = 0; i < rovers.Length; i++)
            {
                validationMsg = "OK";
                if (rovers[i].roverCoordinatValidation == RoverCoordinatValidation.INVALID)
                {
                    validationMsg = "FAIL -> LEFT THE MAP";
                }
                CommonOperations.WriteConsole(rovers[i].id + ", " + rovers[i].name + ", " + rovers[i].position + ", " + rovers[i].direction + ", " + rovers[i].state + ", " + validationMsg + ", " + new String(rovers[i].command), ConsoleWriteType.N);
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Enter rover position and direction
 /// </summary>
 /// <param name="plateauSize">Plateau Size</param>
 /// <param name="roverID">Rover ID</param>
 /// <returns></returns>
 private static string[] setRoverPositionsAndDirection(Point plateauSize, int roverID)
 {
     while (true)
     {
         CommonOperations.WriteConsole("Enter starting position and direction for ROVER-" + (roverID + 1) + " (like 2 3 N): ", ConsoleWriteType.N);
         var data = Console.ReadLine().ToString().ToUpper().Split(' ');
         if (int.Parse(data[0]) <= plateauSize.X && int.Parse(data[1]) <= plateauSize.Y && int.Parse(data[0]) > 0 && int.Parse(data[1]) > 0)
         {
             return(data);
         }
         else
         {
             Console.WriteLine("Please, place in plateau size(" + plateauSize + "). Try again");
         }
     }
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Set plateau size by x and y
 /// </summary>
 /// <returns></returns>
 private static Point SetSize()
 {
     while (true)
     {
         CommonOperations.WriteConsole("Enter plateau size (like X Y):", ConsoleWriteType.N);
         string[] size  = Console.ReadLine().ToString().Split(' ');
         Point    point = new Point(int.Parse(size[0]), int.Parse(size[1]));
         if (point.X > 0 && point.Y > 0)
         {
             return(point);
         }
         else
         {
             Console.WriteLine("Please enter greater than zero");
         }
     }
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Show rovers on map
 /// </summary>
 /// <param name="rovers">Processed rovers</param>
 /// <param name="plateauSize">Plateau Size</param>
 public static void ShowRoverOnMap(Rover[] rovers, Point plateauSize)
 {
     for (int i = plateauSize.Y; i > 0; i--)
     {
         for (int k = 1; k <= plateauSize.X; k++)
         {
             var asd = rovers.Any(item => item.position.X == k && item.position.Y == i);
             if (asd)
             {
                 CommonOperations.WriteConsole("X ", ConsoleWriteType.I);
             }
             else
             {
                 CommonOperations.WriteConsole("* ", ConsoleWriteType.I);
             }
         }
         CommonOperations.WriteConsole("", ConsoleWriteType.N);
     }
     CommonOperations.WriteConsole("", ConsoleWriteType.N);
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Create rovers
        /// </summary>
        /// <param name="plateauSize">Plateau Size</param>
        /// <returns></returns>
        public static Rover[] DeclareRovers(Point plateauSize)
        {
            Rover[] rovers;
            CommonOperations.WriteConsole("Enter the rover numbers: ", ConsoleWriteType.I);
            rovers = new Rover[int.Parse(Console.ReadLine())];

            for (int i = 0; i < rovers.Length; i++)
            {
                var enteredData = setRoverPositionsAndDirection(plateauSize, i);
                rovers[i]           = new Rover();
                rovers[i].id        = i + 1;
                rovers[i].name      = "ROVER-" + (i + 1);
                rovers[i].position  = new Point(int.Parse(enteredData[0]), int.Parse(enteredData[1]));
                rovers[i].direction = CalculationOperations.SetDirection(enteredData[2].ToString().ToUpper());
                CommonOperations.WriteConsole("Enter command for ROVER-" + (i + 1) + "(like LLMRM): ", ConsoleWriteType.N);
                rovers[i].command = Console.ReadLine().ToUpper().ToCharArray();
                rovers[i].state   = State.NONE;
                rovers[i].roverCoordinatValidation = RoverCoordinatValidation.VALID;
            }
            return(rovers);
        }