コード例 #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to Rock, Paper, Scissors!");
            Console.Write("Enter your name: ");
            string userName = Console.ReadLine();

            Validator.GetUserName(userName);

            do
            {
                string playerSelection = RoshamboApp.StartRoshamboApp();

                string userRoshambo = UserPlayer.GenerateRoshambo();

                UserPlayer player = new UserPlayer(userName, userRoshambo);

                int roshamboValue = 0;

                if (playerSelection == "b")
                {
                    roshamboValue   = Bababooie.GetRoshamboValue();
                    playerSelection = "Bababooie";
                }

                if (playerSelection == "l")
                {
                    roshamboValue   = 1;
                    playerSelection = "Left Shark";
                }

                Console.WriteLine($"{player.UserName}: {player.RoshamboValue}");
                Console.WriteLine($"{playerSelection}: {roshamboValue}");

                if (userRoshambo == "1" && roshamboValue == 1)
                {
                    Console.WriteLine("Draw!");
                }
                if ((userRoshambo == "1" && roshamboValue == 2) || (userRoshambo == "2" && roshamboValue = 1))
                {
                    Console.WriteLine($"{playerSelection} wins!");
                }
                if ((userRoshambo == "1" && roshamboValue == 3) || (userRoshambo == "2" && roshamboValue = 1))
                {
                    Console.WriteLine($"{player.UserName} wins!");
                }
                if (userRoshambo == "2" && roshamboValue == 1)
                {
                    Console.WriteLine("Draw!");
                }


                Console.Write("Play again? (y/n): ");
            } while (Console.ReadLine().Equals("y", StringComparison.OrdinalIgnoreCase));


            Console.WriteLine("Goodbye.");
            Console.ReadKey();
        }
コード例 #2
0
        static void Main(string[] args)
        {
            UserPlayer user = new UserPlayer();

            Prompts.SayHello();
            Prompts.GetUserName(user);

            bool whichOppenent = RoshamboApp.AskForOppenent();

            if (whichOppenent == true)
            {
                MatchupVsOpponent1.DecideWinner(user);
            }


            else
            {
                MatchupVsOppenent2.DecideWinner(user);
            }
        }
コード例 #3
0
        public static void DecideWinner(UserPlayer user)
        {
            int userWinTally     = 0;
            int computerWinTally = 0;

            bool loop = true;

            while (loop)
            {
                //Rock - 1, Paper - 2, Scissors - 3

                Opponent2 opponent2 = new Opponent2("");         //Opponent 1 Instance

                int result  = (int)user.GenerateRoshambo();      //Returns User's Enum, and casts into an interger
                int result2 = (int)opponent2.GenerateRoshambo(); //Returns Opponent's 1 Enum (Rock), and casts into an interger

                #region RPS Outcomes

                if (result == 1 && result2 == 2)
                {
                    Console.Clear();
                    Console.WriteLine("\tPaper covers rock");
                    Console.WriteLine("\t" + opponent2.Name + " beats " + user.Name);
                    computerWinTally++;
                    Console.WriteLine("\tYou are " + userWinTally + " and " + computerWinTally + " against " + opponent2.Name);
                }

                else if (result == 1 && result2 == 3)
                {
                    Console.Clear();
                    Console.WriteLine("\tRock beats scissors");
                    Console.WriteLine("\t" + user.Name + " beats " + opponent2.Name);
                    userWinTally++;
                    Console.WriteLine("\tYou are " + userWinTally + " and " + computerWinTally + " against " + opponent2.Name);
                }
                else if (result == 1 && result2 == 1)
                {
                    Console.Clear();
                    Console.WriteLine("\tDraw");
                    Console.WriteLine("\tYou are " + userWinTally + " and " + computerWinTally + " against " + opponent2.Name);
                }

                else if (result == 2 && result2 == 1)
                {
                    Console.Clear();
                    Console.WriteLine("\tPaper covers rock");
                    Console.WriteLine("\t" + user.Name + " beats " + opponent2.Name);
                    userWinTally++;
                    Console.WriteLine("\tYou are " + userWinTally + " and " + computerWinTally + " against " + opponent2.Name);
                }

                else if (result == 2 && result2 == 2)
                {
                    Console.Clear();
                    Console.WriteLine("\tDraw");
                    Console.WriteLine("\tYou are " + userWinTally + " and " + computerWinTally + " against " + opponent2.Name);
                }

                else if (result == 2 && result2 == 3)
                {
                    Console.Clear();
                    Console.WriteLine("\tScissors cuts paper");
                    Console.WriteLine("\t" + opponent2.Name + " beats " + user.Name);
                    computerWinTally++;
                    Console.WriteLine("\tYou are " + userWinTally + " and " + computerWinTally + " against " + opponent2.Name);
                }

                else if (result == 3 && result2 == 1)
                {
                    Console.Clear();
                    Console.WriteLine("\tRock beats scissors");
                    Console.WriteLine("\t" + opponent2.Name + " beats " + user.Name);
                    computerWinTally++;
                    Console.WriteLine("\tYou are " + userWinTally + " and " + computerWinTally + " against " + opponent2.Name);
                }

                else if (result == 3 && result2 == 2)
                {
                    Console.Clear();
                    Console.WriteLine("\tScissors cuts paper");
                    Console.WriteLine("\t" + user.Name + " beats " + opponent2.Name);
                    userWinTally++;
                    Console.WriteLine("\tYou are " + userWinTally + " and " + computerWinTally + " against " + opponent2.Name);
                }

                else if (result == 3 && result2 == 3)
                {
                    Console.Clear();
                    Console.WriteLine("\tDraw");
                }
                #endregion

                bool playAgain = Prompts.AskToPlayAgain();
                if (playAgain == true)
                {
                    loop = true;
                }

                else
                {
                    Console.WriteLine("Have a good day!");
                    System.Environment.Exit(1);
                }
            }
        }
コード例 #4
0
 public static void GetUserName(UserPlayer user)
 {
     Console.WriteLine("What is your name?\n");
     user.Name = Console.ReadLine();
 }