예제 #1
0
        public void Play()
        {
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine("Welcome to the RPS Championships!" + "\n");
            Console.ResetColor();

            HumanPlayer human = new HumanPlayer();

            Console.ForegroundColor = ConsoleColor.DarkCyan;
            Console.Write("Enter your name: ");
            human.Name = Console.ReadLine();

            do
            {
                Player opponent = GetPlayer();

                RPS humanChoice  = human.GenerateRPS();
                RPS playerChoice = opponent.GenerateRPS();

                Console.WriteLine($"You chose: {humanChoice}");
                Console.WriteLine($"Opponent chose: {playerChoice}");

                if (humanChoice == RPS.Rock && playerChoice == RPS.Rock)
                {
                    Console.WriteLine("Draw!");
                }
                else if (humanChoice == RPS.Paper && playerChoice == RPS.Paper)
                {
                    Console.WriteLine("Draw!");
                }
                else if (humanChoice == RPS.Scissors && playerChoice == RPS.Scissors)
                {
                    Console.WriteLine("Draw!");
                }
                else if (humanChoice == RPS.Paper && playerChoice == RPS.Rock)
                {
                    Console.WriteLine("You win!");
                    HumanScore++;
                }
                else if (humanChoice == RPS.Scissors && playerChoice == RPS.Paper)
                {
                    Console.WriteLine("You win!");
                    HumanScore++;
                }
                else if (humanChoice == RPS.Rock && playerChoice == RPS.Scissors)
                {
                    Console.WriteLine("You win!");
                    HumanScore++;
                }
                else if (humanChoice == RPS.Rock && playerChoice == RPS.Paper)
                {
                    Console.WriteLine("You lose!");
                    OpponentScore++;
                }
                else if (humanChoice == RPS.Paper && playerChoice == RPS.Scissors)
                {
                    Console.WriteLine("You lose!");
                    OpponentScore++;
                }
                else if (humanChoice == RPS.Scissors && playerChoice == RPS.Rock)
                {
                    Console.WriteLine("You lose!");
                    OpponentScore++;
                }



                Console.WriteLine($"Your score: {HumanScore}");
                Console.WriteLine($"Opponent score: {OpponentScore}");
            } while (PlayAgain());
        }