コード例 #1
0
ファイル: PlayerGuile.cs プロジェクト: et8111/Lab13
 public override Roshambo generateRoshambo()
 {
     Ro = Roshambo.rock;
     return(Ro);
 }
コード例 #2
0
 public theRock(string Name, Roshambo Roshambo) : base(Name, Roshambo)
 {
 }
コード例 #3
0
 public User(string name, Roshambo roshambo) : base(name, roshambo)
 {
     this.Name     = name;
     this.Roshambo = Roshambo;
 }
コード例 #4
0
 protected Player(string name, Roshambo roshambo)
 {
     this.name     = name;
     this.roshambo = roshambo;
 }
コード例 #5
0
        static void Main(string[] args)
        {
            //variables

            string     playAgainst;
            Player     opp;
            Player     user;
            int        oppWins = 0, userWins = 0, draws = 0;
            IValidator validator = new Validator();

            Console.WriteLine("WELCOME TO ROCK PAPER SCISSORS APP");
            Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");

            Console.Write("Enter your name: ");

            user = new ThirdPlayer(Console.ReadLine()); //This reads the literal user types in to save as the name of the 3rd player


            Console.Write("\nWould you like to play against Puppies or Kittens? (p/k)");
            playAgainst = Console.ReadLine().ToLower();
            while (!validator.IsValidPlayAgainst(playAgainst))
            {
                Console.WriteLine("\nError: That was an invalid team name. Please try again.");
                Console.Write("Puppies or Kittens? Enter (p or k)");
                playAgainst = Console.ReadLine().ToLower();
            }
            if (playAgainst == "p")
            {
                opp = new Puppies();
            }
            else
            {
                opp = new Kittens();
            }
            string again = "y";

            while (again != "n")
            {
                Roshambo userChoice = user.GenerateRoshambo();
                Roshambo oppChoice  = opp.GenerateRoshambo();



                if (oppChoice == userChoice)
                {
                    Console.WriteLine("DRAW!");
                    draws++;
                }
                else if (oppChoice == Roshambo.Paper && userChoice == Roshambo.Rock)
                {
                    Console.WriteLine($"{opp.Name} WINS!");
                    oppWins++;
                }
                else if (oppChoice == Roshambo.Rock && userChoice == Roshambo.Scissors)
                {
                    Console.WriteLine($"{opp.Name} WINS!");
                    oppWins++;
                }
                else if (oppChoice == Roshambo.Scissors && userChoice == Roshambo.Paper)
                {
                    Console.WriteLine($"{opp.Name} WINS!");
                    oppWins++;
                }
                else if (userChoice == Roshambo.Rock && oppChoice == Roshambo.Scissors)
                {
                    Console.WriteLine($"{user.Name} WINS!");
                    userWins++;
                }
                else if (userChoice == Roshambo.Paper && oppChoice == Roshambo.Rock)
                {
                    Console.WriteLine($"{user.Name} WINS!");
                    userWins++;
                }
                else if (userChoice == Roshambo.Scissors && oppChoice == Roshambo.Paper)
                {
                    Console.WriteLine($"{user.Name} WINS!");
                    userWins++;
                }

                //Displays Scores & player choices
                Console.WriteLine("\nSCORES");
                Console.WriteLine("===========");
                Console.WriteLine($"{user.Name} chose {userChoice}");
                Console.WriteLine($"{opp.Name} chose {oppChoice}");
                Console.WriteLine($"{user.Name} Wins: {userWins}");
                Console.WriteLine($"{opp.Name} Wins: {oppWins}");
                Console.WriteLine($"Draw Games: {draws}");

                Console.WriteLine("Would you like to play again?(y/n)");
                again = Console.ReadLine().ToLower();
                while (again != "y" && again != "n")
                {
                    Console.WriteLine("Error: That input was not valid. Please try again.");
                    Console.WriteLine("Would you like to play again?(y/n)");
                    again = Console.ReadLine().ToLower();
                }
            }
            int x = (int)Roshambo.Rock;

            Console.WriteLine(x);

            //Pause before exit
            Console.WriteLine("Press any key to exit. .");
            Console.ReadKey();
        }
コード例 #6
0
        static void Main(string[] args)
        {
            UserSelector userSelector = new UserSelector();

            RockSelector rockSelector = new RockSelector();

            RandomSelector randomSelector = new RandomSelector();

            int tieCounter  = 0;
            int winCounter  = 0;
            int lossCounter = 0;


            //rockSelector.generateRoShambo();
            bool truth = true;

            while (truth)
            {
                Console.WriteLine("Do you want to play against rock or random?");
                string input = Console.ReadLine().ToLower();

                if (!Validator.IntChecker(input))
                {
                    if (input == "rock")
                    {
                        Roshambo roshambo = userSelector.generateRoShambo();
                        Roshambo rock     = rockSelector.generateRoShambo();
                        if ((rock.CompareTo(roshambo)) == 0)
                        {
                            Console.WriteLine($"{userSelector.Name} chose {roshambo}");
                            Console.WriteLine($"{rockSelector.Name} chose {rock}");
                            Console.WriteLine("Tie!\n\n");
                            tieCounter++;
                        }
                        else
                        {
                            if (roshambo == Roshambo.paper)
                            {
                                Console.WriteLine($"{userSelector.Name} chose {roshambo}");
                                Console.WriteLine($"{rockSelector.Name} chose {rock}");
                                Console.WriteLine("You Win!\n\n");
                                winCounter++;
                            }
                            else if (roshambo == Roshambo.scissors)
                            {
                                Console.WriteLine($"{userSelector.Name} chose {roshambo}");
                                Console.WriteLine($"{rockSelector.Name} chose {rock}");
                                Console.WriteLine("You Lose!\n\n");
                                lossCounter++;
                            }
                        }
                    }
                    else if (input == "random")
                    {
                        Roshambo rando    = randomSelector.generateRoShambo();
                        Roshambo roshambo = userSelector.generateRoShambo();

                        if ((rando.CompareTo(roshambo)) == 0)
                        {
                            Console.WriteLine($"{userSelector.Name} chose {roshambo}");
                            Console.WriteLine($"{randomSelector.Name} chose {rando}");
                            Console.WriteLine("Tie!\n\n");
                            tieCounter++;
                        }
                        else
                        {
                            if (rando == Roshambo.rock)
                            {
                                if (roshambo == Roshambo.paper)
                                {
                                    Console.WriteLine($"{userSelector.Name} chose {roshambo}");
                                    Console.WriteLine($"{randomSelector.Name} chose {rando}");
                                    Console.WriteLine("You Win!\n\n");
                                    winCounter++;
                                }
                                else if (roshambo == Roshambo.scissors)
                                {
                                    Console.WriteLine($"{userSelector.Name} chose {roshambo}");
                                    Console.WriteLine($"{randomSelector.Name} chose {rando}");
                                    Console.WriteLine("You Lose!\n\n");
                                    lossCounter++;
                                }
                            }
                            else if (rando == Roshambo.paper)
                            {
                                if (roshambo == Roshambo.scissors)
                                {
                                    Console.WriteLine($"{userSelector.Name} chose {roshambo}");
                                    Console.WriteLine($"{randomSelector.Name} chose {rando}");
                                    Console.WriteLine("You Win!\n\n");
                                    winCounter++;
                                }
                                else if (roshambo == Roshambo.rock)
                                {
                                    Console.WriteLine($"{userSelector.Name} chose {roshambo}");
                                    Console.WriteLine($"{randomSelector.Name} chose {rando}");
                                    Console.WriteLine("You Lose!\n\n");
                                    lossCounter++;
                                }
                            }
                            else if (rando == Roshambo.scissors)
                            {
                                if (roshambo == Roshambo.rock)
                                {
                                    Console.WriteLine($"{userSelector.Name} chose {roshambo}");
                                    Console.WriteLine($"{randomSelector.Name} chose {rando}");
                                    Console.WriteLine("You Win!\n\n");
                                    winCounter++;
                                }
                                else if (roshambo == Roshambo.paper)
                                {
                                    Console.WriteLine($"{userSelector.Name} chose {roshambo}");
                                    Console.WriteLine($"{randomSelector.Name} chose {rando}");
                                    Console.WriteLine("You Lose!\n\n");
                                    lossCounter++;
                                }
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("\n\n\t\t\t\t     Invalid input, we'll restart\n\n");
                        continue;
                    }
                }
                else
                {
                    Console.WriteLine("\n\n\t\t\t\t     Invalid input, we'll restart\n\n");
                    continue;
                }
                truth = Continue();
            }
            Console.WriteLine($"\n\n\t\t\t     The amount of Wins during this session was {winCounter}.");
            Console.WriteLine($"\n\n\t\t\t     The amount of Losses during this session was {lossCounter}.");
            Console.WriteLine($"\n\n\t\t\t     The amount of Ties during this session was {tieCounter}.");
        }