Пример #1
0
        public Grid GetGridFromInputs()
        {
            Grid.GridBuilder builder = Grid.Builder();

            GetSafeUserInput(builder, "grid size", v => { builder.WithSize(v); });
            GetSafeUserInput(builder, "number of components", v => { builder.WithComponentCount(v); });

            for (int i = 1; i <= builder.Count; i++)
            {
                GetSafeUserInputForCoordinate(builder, "component" + i + "'s coordinate as X,Y", c => { builder.AddComponent(new Component(c)); });
            }
            GetSafeUserInputForCoordinate(builder, "rover's coordinate X,Y", c => { builder.WithRover(new Rover(c)); });

            return(builder.Build());
        }
Пример #2
0
        private void GetSafeUserInputForCoordinate(Grid.GridBuilder builder, string label, Action <Coordinate> setFunc)
        {
            bool valueSet = false;

            Console.WriteLine("Please enter " + label + " : ");
            while (!valueSet)
            {
                try
                {
                    setFunc(GetCoordinateValue());
                    valueSet = true;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }