Esempio n. 1
0
        public static void Main()
        {
            string userInput;
            bool   gameFinished = false;
            string gameResult;

            while (!gameFinished)
            {
                Console.WriteLine("Make your choice! (Rock/Paper/Scissors/Quit)");
                userInput = Console.ReadLine().ToLower();

                if (userInput == "rock" || userInput == "paper" || userInput == "scissors")
                {
                    RockPaperScissors round = new RockPaperScissors(userInput);

                    switch (round.GetGameResult())
                    {
                    case "win":
                        gameResult = "Congratulations, your " + round.UserChoice + " beat the computer's " + round.ComputerChoice + ".";
                        break;

                    case "loss":
                        gameResult = "Sorry, your " + round.UserChoice + " lost to the computer's " + round.ComputerChoice + ".";
                        break;

                    case "draw":
                        gameResult = "How about that, its a draw. You both chose " + round.UserChoice + ".";
                        break;

                    default:
                        gameResult = "There was an error determining a win.";
                        break;
                    }
                }
                else if (userInput == "quit")
                {
                    gameFinished = true;
                    gameResult   = "Thanks for playing, goodbye.";
                }
                else
                {
                    gameResult = "Sorry, that was an invalid option.";
                }

                Console.WriteLine(gameResult);
            }
        }
Esempio n. 2
0
        public void UIGame()
        {
            bool endGame             = false;
            RockPaperScissors myGame = new RockPaperScissors();

            while (endGame == false)
            {
                Console.WriteLine("Do you want to play 1 or 2 player? Enter 1 or 2");
                ConsoleKeyInfo choice = Console.ReadKey(true);
                if (choice.Key == ConsoleKey.D1)
                {
                    Console.WriteLine("1 Player🧟‍♂️ Game!");
                    Console.WriteLine("Player: Enter 0 for rock, 1 for paper or 2 for scissors");
                    ConsoleKeyInfo player       = Console.ReadKey(true);
                    Listof_Choices playerNumber = (Listof_Choices)Char.GetNumericValue(player.KeyChar);
                    Listof_Results result       = myGame.Play(playerNumber);
                    Console.WriteLine("{0} Wins! 🏄🏽‍♂️", result);
                    break;
                }

                if (choice.Key == ConsoleKey.D2)
                {
                    Console.WriteLine("2 Player🧟‍♂️ Game!");
                    Console.WriteLine("Player 1: Enter 0 for rock, 1 for paper or 2 for scissors");
                    ConsoleKeyInfo player1       = Console.ReadKey(true);
                    Listof_Choices player1Number = (Listof_Choices)Char.GetNumericValue(player1.KeyChar);
                    Console.WriteLine("Player 2: Enter 0 for rock, 1 for paper or 2 for scissors");
                    ConsoleKeyInfo player2       = Console.ReadKey(true);
                    Listof_Choices player2Number = (Listof_Choices)Char.GetNumericValue(player2.KeyChar);
                    Listof_Results result        = myGame.Play(player1Number, player2Number);
                    Console.WriteLine("{0} Wins! 🏄🏽‍♂️", result);

                    Console.WriteLine("🏄🏽");
                    break;
                }
                Console.WriteLine("Opps i said...");
            }
        }