static void Main(string[] args)
        {
            Player randomPlayer = new RandomPlayer("Random Balboa");
            //randomPlayer.Name = "Random Balboa";

            Player rockPlayer = new RockPlayer("Rocky Balboa");
            //rockPlayer.Name = "Rockey Balboa";

            UserPlayer userPlayer = new UserPlayer();

            Console.Write("Enter your Name"); // user input
            userPlayer.Name = Console.ReadLine();;

            Console.WriteLine("Select your rockPlayer!");
            Console.WriteLine("1). Rocky Balboa");
            Console.WriteLine("2). Random Balboa");

            string userInput = Console.ReadLine();

            switch (userInput)
            {
            case "1":
                Play(userPlayer, new RockPlayer("Rocky Balboa"));
                break;

            case "2":
                Play(userPlayer, new RandomPlayer("Random Balboa"));
                break;
            }
        }
示例#2
0
        static void Main(string[] args)
        {
            bool repeat = true;

            while (repeat == true)
            {
                Roshambo      rps = new Roshambo();         //Roshambo object rps
                DwayneJohnson ro  = new DwayneJohnson(rps); //Dwayne Johnson object ro
                GrantThompson ra  = new GrantThompson(rps); //Grant Thompson object ra
                UserPlayer    uc  = new UserPlayer(rps);    //User object uc
                RoshamboApp   op  = new RoshamboApp();
                Console.WriteLine("Welcome to Rock, Paper, Scissors! Enter your name:");
                string userName = Console.ReadLine();
                Console.WriteLine("Thanks {0}! Would you like to play against {1} or {2} (DJ/GT)?", userName, ro.GetName(), ra.GetName());
                string userOpponent = op.OpponentName();
                Console.WriteLine("Your opponent is {0}. Rock, paper, or scissors (R/P/S)?", userOpponent);
                Console.WriteLine(userName + ": " + uc.GenerateRoshambo());
                if (userOpponent == "Dwayne Johnson")
                {
                    Console.WriteLine(ro.GetName() + ": " + ro.GenerateRoshambo()); //generate Roshambo using the method defined in the Dwayne Johnson class
                }
                if (userOpponent == "Grant Thompson")
                {
                    Console.WriteLine(ra.GetName() + ": " + ra.GenerateRoshambo()); //generate Roshambo using the method defined in the Grant Thompson class
                }
                repeat = DoAgain();
            }
            Console.WriteLine("Thanks for playing! Goodbye.");
        }
        public static void Play(UserPlayer userPlayer, Player choosenPlayer)
        {
            int i = 0;

            //int rockyWins = 0;
            //int randomWins = 0;
            //int ties = 0;

            while (i < 10)// this means we will run it 10 times.
            {
                Console.WriteLine("Pick Rock, Paper, Scissors");
                string rocky  = choosenPlayer.GenerateRoshambo();
                string random = userPlayer.GenerateRoshambo();

                if (rocky == "Rock" && random == "Rock")
                {
                    Console.WriteLine($"{userPlayer.Name} selected {random}");
                    Console.WriteLine(($"{choosenPlayer.Name} selected {rocky}"));
                    Console.WriteLine("Tie");
                }

                else if (rocky == "Rock" && random == "Paper")
                {
                    Console.WriteLine($"{userPlayer.Name} selected {random}");
                    Console.WriteLine(($"{choosenPlayer.Name} selected {rocky}"));
                    Console.WriteLine($"{choosenPlayer.Name} Wins!");
                }
                else if (rocky == "Rock" && random == "Scissors")
                {
                    Console.WriteLine($"{userPlayer.Name} selected {random}");
                    Console.WriteLine(($"{choosenPlayer.Name} selected {rocky}"));
                    Console.WriteLine($"{choosenPlayer.Name} Wins!");
                }
                else if (rocky == "Rock" && random == "Paper")
                {
                    Console.WriteLine($"{userPlayer.Name} selected {random}");
                    Console.WriteLine(($"{choosenPlayer.Name} selected {rocky}"));
                    Console.WriteLine($"{userPlayer.Name} Wins!");
                }
                i++;  // this is to get out of the while loop
            }
        }
示例#4
0
        public void BeginRoshambo()
        {
            UserPlayer user = new UserPlayer();

            user.Name = Program.GetUserInput("Please enter your name.");
            bool goAgain = true;

            while (goAgain)
            {
                Console.Clear();
                Player opponent = ChooseOpponent();
                user.Roshambo = user.GenerateRoshambo();

                opponent.GenerateRoshambo();
                Console.WriteLine($"{opponent.ReturnName()} has thrown {opponent.GenerateRoshambo()}");
                Console.WriteLine($"{user.Name} has thrown {user.Roshambo}");
                if (user.Winner(opponent))
                {
                    Console.WriteLine($"{user.ReturnName()} is the winner!");
                }
                else if (opponent.Winner(user))
                {
                    Console.WriteLine($"{opponent.ReturnName()} is the winner!");
                }
                else
                {
                    Console.WriteLine("Tie! Nobody wins!");
                }

                string quitChoice;
                Console.WriteLine($"You have a total of {user.Wins()} wins, {user.Losses()} losses, and {user.Ties()} ties.");
                Console.WriteLine("Enter (Q)uit to exit, or any other key to run again");

                quitChoice = Console.ReadLine().Trim();

                if (quitChoice.ToLower() == "q" || quitChoice.ToLower() == "quit")
                {
                    goAgain = false;
                }
            }
        }
示例#5
0
        public void RunApp()
        {
            Console.WriteLine("Enter your name");
            string name = Console.ReadLine();

            Console.WriteLine("Would you like to play against player 1 or player 2(enter 1 for player 1, 2 for player 2): ");
            int userChoice;

            userChoice = IsValidIntEntered(Console.ReadLine());
            char loopBreaker;
            int  userPlayerWins = 0;
            int  compPlayerWins = 0;


            do
            {
                if (userChoice == 1)
                {
                    Console.WriteLine("Rock, Paper, Scissors: (1 = rock, 2 = paper, 3 = scissors)");
                    string     choice     = Console.ReadLine();
                    UserPlayer user       = new UserPlayer(name, choice);
                    Player1    compPlayer = new Player1();

                    if (user.RoshamboValue == Roshambo.rock)
                    {
                        Console.WriteLine($"{user.Name}: {user.RoshamboValue}");
                        Console.WriteLine($"{compPlayer.Name}: {compPlayer.RoshamboValue}");

                        Console.WriteLine("Neither player wins draw");
                    }
                    else if (user.RoshamboValue == Roshambo.paper)
                    {
                        Console.WriteLine($"{user.Name}: {user.RoshamboValue}");
                        Console.WriteLine($"{compPlayer.Name}: {compPlayer.RoshamboValue}");
                        Console.WriteLine($"{user.Name} wins");
                        userPlayerWins++;
                    }
                    else
                    {
                        Console.WriteLine($"{user.Name}: {user.RoshamboValue}");
                        Console.WriteLine($"{compPlayer.Name}: {compPlayer.RoshamboValue}");
                        Console.WriteLine($"{compPlayer.Name} wins");
                        compPlayerWins++;
                    }

                    Console.ReadLine();
                }
                else
                {
                    Console.WriteLine("Rock, Paper, Scissors: (1 = rock, 2 = paper, 3 = scissors)");
                    string     choice       = Console.ReadLine();
                    UserPlayer user         = new UserPlayer(name, choice);
                    Player2    compPlayer   = new Player2();
                    Player3    playerResult = new Player3();
                    compPlayer.RoshamboValue = playerResult.RoshamboChoice(compPlayer);
                    if (user.RoshamboValue == Roshambo.rock)
                    {
                        if (compPlayer.RoshamboValue == Roshambo.rock)
                        {
                            Console.WriteLine($"{user.Name}: {user.RoshamboValue}");
                            Console.WriteLine($"{compPlayer.Name}: {compPlayer.RoshamboValue}");
                            Console.WriteLine("Its a tie!");
                        }
                        else if (compPlayer.RoshamboValue == Roshambo.paper)
                        {
                            Console.WriteLine($"{user.Name}: {user.RoshamboValue}");
                            Console.WriteLine($"{compPlayer.Name}: {compPlayer.RoshamboValue}");
                            Console.WriteLine("Player 2 wins!");
                            compPlayerWins++;
                        }
                        else
                        {
                            Console.WriteLine($"{user.Name}: {user.RoshamboValue}");
                            Console.WriteLine($"{compPlayer.Name}: {compPlayer.RoshamboValue}");
                            Console.WriteLine($"{user.Name} wins!");
                            userPlayerWins++;
                        }
                    }
                    else if (user.RoshamboValue == Roshambo.paper)
                    {
                        if (compPlayer.RoshamboValue == Roshambo.rock)
                        {
                            Console.WriteLine($"{user.Name}: {user.RoshamboValue}");
                            Console.WriteLine($"{compPlayer.Name}: {compPlayer.RoshamboValue}");
                            Console.WriteLine($"{user.Name} wins!");
                            userPlayerWins++;
                        }
                        else if (compPlayer.RoshamboValue == Roshambo.paper)
                        {
                            Console.WriteLine($"{user.Name}: {user.RoshamboValue}");
                            Console.WriteLine($"{compPlayer.Name}: {compPlayer.RoshamboValue}");
                            Console.WriteLine("Its a tie!");
                        }
                        else
                        {
                            Console.WriteLine($"{user.Name}: {user.RoshamboValue}");
                            Console.WriteLine($"{compPlayer.Name}: {compPlayer.RoshamboValue}");
                            Console.WriteLine("Player 2 wins!");
                            compPlayerWins++;
                        }
                    }
                    else
                    {
                        if (compPlayer.RoshamboValue == Roshambo.rock)
                        {
                            Console.WriteLine($"{user.Name}: {user.RoshamboValue}");
                            Console.WriteLine($"{compPlayer.Name}: {compPlayer.RoshamboValue}");
                            Console.WriteLine("Player 2 wins!");
                            compPlayerWins++;
                        }
                        else if (compPlayer.RoshamboValue == Roshambo.paper)
                        {
                            Console.WriteLine($"{user.Name}: {user.RoshamboValue}");
                            Console.WriteLine($"{compPlayer.Name}: {compPlayer.RoshamboValue}");
                            Console.WriteLine($"{user.Name} wins!");
                            userPlayerWins++;
                        }
                        else
                        {
                            Console.WriteLine($"{user.Name}: {user.RoshamboValue}");
                            Console.WriteLine($"{compPlayer.Name}: {compPlayer.RoshamboValue}");
                            Console.WriteLine("Its a tie!");
                        }
                    }
                }
                Console.WriteLine("Do you wish to continue(enter y/n): "); //ask user to if they want to continue
                loopBreaker = IsValidLoopBreaker(Console.ReadLine());      //storing answer and if it's valid input
                Console.ReadLine();
            } while (loopBreaker == 'y');

            Console.WriteLine($"{name} won {userPlayerWins} games");
            Console.WriteLine($"{name} lost {compPlayerWins} games");
        }