Exemple #1
0
        public void PlayRPS()
        {
            Random r = new Random();

            //setup
            Console.WriteLine("Welcome to Roshambo EXTREME!\n" +
                              "\nWhat's your name? HURRY GO!");
            string uName = Console.ReadLine();
            User   user  = new User(uName);
            Player opponent;

            Players.Add(user);

            int choice = 0;

            Console.WriteLine($"\nWhat up {user.Name}! Who would you like to play?!??!!\n" +
                              $"\n1)  Ranbo" +
                              $"\n2)  RockMan" +
                              $"\nChoose 1 or 2:");
            Validator.IsInRangeIndex(Console.ReadLine(), 1, 2, out choice);
            if (choice == 0)
            {
                opponent = new Ranbo();
            }
            else
            {
                opponent = new RockMan();
            }
            Players.Add(opponent);

            while (true)
            {
                //generate win or loss along with encouragement.

                int    noiceNum = r.Next(0, (RightOn.Length - 1));
                int    bumNum   = r.Next(0, (Bummer.Length - 1));
                string noice    = RightOn[noiceNum];
                string doh      = Bummer[bumNum];

                string uChoice = user.generateRoshambo();
                string oChoice = opponent.generateRoshambo();
                int    match   = WhoWon(uChoice, oChoice);

                Console.WriteLine($"\n{user.Name} picks {uChoice}!" +
                                  $"\n{opponent.Name} picks {oChoice}!\n");

                switch (match)
                {
                case 0:
                    Console.WriteLine("It's a tie!");
                    break;

                case 1:
                    Console.WriteLine($"You win! {noice}");
                    user.Wins++;
                    break;

                case 2:
                    Console.WriteLine($"{opponent.Name} wins...{doh}");
                    user.Losses++;
                    break;

                default:
                    Console.WriteLine("EXCRUCIATINGLY TERRIBLE FAILURE");
                    break;
                }
                Console.WriteLine("\nDo you want to play again? (Y/N)");
                if (Validator.YayOrNay(Console.ReadLine().ToUpper()))
                {
                    continue;
                }
                else
                {
                    break;
                }
            }
            Console.WriteLine($"You won {user.Wins} times and lost {user.Losses} times.");
            Console.WriteLine("Later!");
        }