Example #1
0
        public void GridSetup()
        {
            while (true)
            {
                try {
                    _userIo.WriteLine("What size would you like to make the grid?\n" +
                                      $"Max size: {MAX_GRID_SIZE}x{MAX_GRID_SIZE} (Ex. '3 4' makes a 3x4 grid.)");
                    var input = GetUserInput().Split(' ');

                    if (input.Length != MAX_GRID_INPUT_LENGTH || !IsValidGridInput(input))
                    {
                        throw new InvalidInputException("Invalid grid size input.");
                    }

                    if (IsValidGridSize(input))
                    {
                        throw new InvalidInputException($"Invalid grid size input, please use a valid grid size 0 < Length/Width < {MAX_GRID_SIZE}.");
                    }

                    GridWidth  = int.Parse(input[0]);
                    GridHeight = int.Parse(input[1]);

                    ClearAndWriteLine($"Grid was initialized with size {GridWidth}x{GridHeight}");

                    break;
                }
                catch (InvalidInputException invalidInputException) {
                    ClearAndWriteLine(invalidInputException.Message);
                }
            }
        }
        private string GetCustomerName(IUserIO io)
        {
            //TODO: Move to UI
            string userIn;
            bool   firstTime = true;

            do
            {
                if (!firstTime)
                {
                    io.WriteLine("Invalid input. Names may only contain letters, numbers, spaces, commas, and periods.");
                }
                userIn    = io.GetString("Please enter your name.");
                firstTime = false;
            } while (!userIn.All(c => Char.IsLetterOrDigit(c) || c == ' ' || c == ',' || c == '.'));
            return(userIn);
        }
        private DateTime GetFutureDate(IUserIO io)
        {
            //TODO: move to UI
            DateTime target;
            bool     firstTry = true;

            do
            {
                if (!firstTry)
                {
                    io.WriteLine("Order date must be in the future.");
                }
                target   = io.GetDate("Please enter a date for the order:");
                firstTry = false;
            } while (target < DateTime.Now);
            return(target);
        }