示例#1
0
        public static UserReply GetUserGuess()
        {
            UserReply result;

            System.Console.WriteLine("Please type your next guess <A B C D> or 'Q' to quit:");
            string userInput = System.Console.ReadLine();
            bool   quitGame  = InputValidationUtils.QuitValidator(userInput);

            while (!quitGame && !InputValidationUtils.ValidateUserInput(userInput))
            {
                System.Console.WriteLine("Input guess is incorrect. Please insert a new input:");
                userInput = System.Console.ReadLine();
                quitGame  = InputValidationUtils.QuitValidator(userInput);
            }

            if (!quitGame)
            {
                result = new UserReply(quitGame, IOConvertors.GuessStringToPinArrayConvertor(userInput));
            }
            else
            {
                result = new UserReply(quitGame, null);
            }

            return(result);
        }
示例#2
0
        public static bool PromptNewGameQuery()
        {
            System.Console.WriteLine("Would you like to start a new game? <Y/N>");
            string userInput = System.Console.ReadLine();

            while (!InputValidationUtils.YesNoValidator(userInput))
            {
                System.Console.WriteLine("Input is incorrect. please reenter decision:");
                userInput = System.Console.ReadLine();
            }

            return("Y".Equals(userInput));
        }
        public static ushort GetNumberOfGuesses()
        {
            ushort inputUshortNumber;

            System.Console.WriteLine("Please insert how many guesses you want to have (between {0} and {1}) in this game: ", GameProperties.MinimumNumberOfTries, GameProperties.MaximumNumberOfTries);
            bool parseResult = ushort.TryParse(System.Console.ReadLine(), out inputUshortNumber);

            while (!parseResult || InputValidationUtils.IsOutOfBound(inputUshortNumber))
            {
                if (!parseResult)
                {
                    System.Console.WriteLine(@"The input that was entered was not the correct type!
Reenter a number:");
                }
                else
                {
                    System.Console.WriteLine(@"Input out of bound please reenter a number:");
                }
                parseResult = ushort.TryParse(System.Console.ReadLine(), out inputUshortNumber);
            }

            return(inputUshortNumber);
        }