コード例 #1
0
        private uint BestOfRequired()
        {
            var yesNoValidator = new YesNoValidator();

            while (!yesNoValidator.Validate(new UserChoice(userChoice)).IsValid)
            {
                Console.WriteLine("\nWould you like to play a \"best-of\" match?");
                string yesNo = Console.ReadLine();
                userChoice = yesNo.ToUpper();

                var message = yesNoValidator.Validate(new UserChoice(userChoice));
                Console.WriteLine(message);
            }

            var yesValidator = new YesValidator();

            if (yesValidator.Validate(new UserChoice(userChoice)).IsValid)
            {
                Console.WriteLine("How many rounds do you want to play?");
                while (!uint.TryParse(Console.ReadLine(), out this.bestOfCounter))
                {
                    Console.WriteLine("Please enter a positive number.");
                }
            }
            this.ClearUserChoice();
            return(bestOfCounter);
        }
コード例 #2
0
        public bool PlayAgain(string yesNo)
        {
            var yesNoValidator = new YesNoValidator();

            Console.WriteLine("Would you like to play again?  ");
            while (!yesNoValidator.Validate(new UserChoice(userChoice)).IsValid)
            {
                var message = yesNoValidator.Validate(new UserChoice(userChoice));
                Console.WriteLine(message);
            }

            if (yesNoValidator.Validate(new UserChoice(userChoice)).IsValid)
            {
                return(true);
            }

            else
            {
                Console.WriteLine("Thanks for playing!");
                return(false);
            }
        }
コード例 #3
0
        private void Introduction()
        {
            Console.WriteLine("Welcome to Rock, Paper, Scissors!");
            var yesNoValidator = new YesNoValidator();

            while (!yesNoValidator.Validate(new UserChoice(userChoice)).IsValid)
            {
                Console.WriteLine("\nDo you need to read the instructions?");
                string instructions = Console.ReadLine();
                userChoice = instructions.ToUpper();

                var message = yesNoValidator.Validate(new UserChoice(userChoice));
                Console.WriteLine(message);

                var yesValidator = new YesValidator();
                if (yesValidator.Validate(new UserChoice(userChoice)).IsValid)
                {
                    this.Instructions();
                    break;
                }
            }
            this.ClearUserChoice();
        }