예제 #1
0
        private ICounter CreateTextCounter(string iterations, string delay)
        {
            if (!NumeralsConverter.IsValidNumber(iterations, 1))
            {
                throw new Exception("Iterations must be numeral of integer greater or equal to 1");
            }

            if (!NumeralsConverter.IsValidNumber(delay, 1))
            {
                throw new Exception("Delay must be numeral of integer greater or equal to 0");
            }

            return(new TextCounter(iterations, delay, GetNewName(CounterType.TextCounter)));
        }
예제 #2
0
        private string GetUserInput(string message, object possibleAnswers)
        {
            bool   answerOk = false;
            string input;

            do
            {
                Console.WriteLine(message);
                input = Console.ReadLine().ToLower();

                if (possibleAnswers is Array)
                {
                    foreach (string a in possibleAnswers as Array)
                    {
                        if (a == input)
                        {
                            answerOk = true;
                            break;
                        }
                    }
                }
                else if (possibleAnswers is int)
                {
                    answerOk = int.TryParse(input, out int t) && (t >= (int)possibleAnswers);
                }
                else if (possibleAnswers is string)
                {
                    answerOk = NumeralsConverter.IsValidNumber(input, int.Parse((string)possibleAnswers));
                }

                if (input == "c")
                {
                    throw new Exception("Canceled");
                }

                if (!answerOk)
                {
                    WrongAnswer();
                }
            } while (!answerOk);

            return(input);
        }