Esempio n. 1
0
        private IChoice GetUserChoise(string userInput)
        {
            char    userChar   = Convert.ToChar(userInput);
            IChoice userChoice = RPSRepository.GetChoiceFromChar(userChar);

            return(userChoice);
        }
Esempio n. 2
0
        private void ExecuteVsTwoPlayers()
        {
            int i = 1;

            while (true)
            {
                try
                {
                    if (_giveName != true)
                    {
                        GetPlayer(1);
                        GetPlayer(2);
                        users = new Users(_players[0], _players[1]);
                        score = new Score(users);
                    }
                    Console.WriteLine("-------------" + i + "em--------------");
                    _giveName = true;
                    var userChoice1 = GetPlayerChoice(_players[0], 0);
                    var userChoice2 = GetPlayerChoice(_players[1], 1);
                    RPSRepository.Outcome outcome = RPSRepository.GetOutcome(userChoice1, userChoice2, users);
                    GiveScore(outcome, score);
                } catch (Exception ex)
                {
                    throw new RPSException("Invalid input" + ex);
                }
                i++;
            }
        }
Esempio n. 3
0
 public void ExecuteVsComputer()
 {
     users = new Users("You", "Computer");
     score = new Score(users);
     while (true)
     {
         Console.WriteLine("\nRock [r] Paper [p] Scissors [s] Quit [q]");
         string userInput = Console.ReadLine();
         try
         {
             var userChoice = GetUserChoise(userInput);
             if (userChoice.Name.Equals("Quit"))
             {
                 break;
             }
             if (userChoice.Name.Equals("Invalid"))
             {
                 continue;
             }
             IChoice randomChoice          = RPSRepository.GetRandomChoice();
             RPSRepository.Outcome outcome = RPSRepository.GetOutcome(userChoice, randomChoice, users);
             GiveScore(outcome, score);
         }
         catch (Exception ex)
         {
             throw new RPSException("Invalid input" + ex);
         }
     }
 }
Esempio n. 4
0
        private IChoice GetPlayerChoice(string player, int number)
        {
            Console.WriteLine("Choice for " + player + ":");
            Console.WriteLine("\nRock [r] Paper [p] Scissors [s] Quit [q]");
            string userInput  = Console.ReadLine();
            char   userChar   = Convert.ToChar(userInput);
            var    userChoice = RPSRepository.GetChoiceFromChar(userChar);

            if (userChoice.Name.Equals("Invalid"))
            {
                Console.WriteLine("Character '" + userInput + "' is not valid");
                GetPlayerChoice(player, number);
            }
            return(userChoice);
        }