コード例 #1
0
ファイル: player.cs プロジェクト: Dratp/RoShamBo
        public static int Compare(Roshambo p1, Roshambo p2)
        {
            int winner = 0;

            if (p1 == p2)
            {
                winner = 0;
            }
            else if (p1 == Roshambo.Rock)
            {
                if (p2 == Roshambo.Paper)
                {
                    winner = 2;
                }
                else
                {
                    winner = 1;
                }
            }
            else if (p1 == Roshambo.Paper)
            {
                if (p2 == Roshambo.Rock)
                {
                    winner = 1;
                }
                else
                {
                    winner = 2;
                }
            }
            else
            {
                if (p2 == Roshambo.Rock)
                {
                    winner = 2;
                }
                else
                {
                    winner = 1;
                }
            }
            return(winner);
        }
コード例 #2
0
 public static string WinOrLose(Roshambo userChoice, Roshambo npc)
 {
     try
     {
         if (userChoice == Roshambo.scissors && npc == Roshambo.paper)
         {
             return("You're a winner.");
         }
         else if (userChoice.Equals(npc))
         {
             return("Tie");
         }
         else if (userChoice == Roshambo.rock && npc == Roshambo.rock)
         {
             return("Tie");
         }
         else if (userChoice == Roshambo.scissors && npc == Roshambo.rock)
         {
             return("You lost.");
         }
         else if (userChoice == Roshambo.rock && npc == Roshambo.scissors)
         {
             return("You're a winner.");
         }
         else if (userChoice == Roshambo.paper && npc == Roshambo.scissors)
         {
             return("You lost.");
         }
         else if (userChoice == Roshambo.paper && npc == Roshambo.rock)
         {
             return("You're a winner.");
         }
         else
         {
             return(WinOrLose(userChoice, npc));
         }
     }
     catch (FormatException)
     {
         Console.WriteLine("Not correct try again.");
         return(WinOrLose(userChoice, npc));
     }
 }
コード例 #3
0
ファイル: UserPlayer.cs プロジェクト: Zach0702/rockpaper
        public UserPlayer(string name, string choice)
        {
            Name = name;
            bool isInvalidInput = true;

            while (isInvalidInput)
            {
                if (Enum.TryParse <Roshambo>(choice, out Roshambo validEnum))
                {
                    RoshamboValue  = validEnum;
                    isInvalidInput = false;
                }
                else
                {
                    Console.WriteLine("ERROR: invalid choice entered");
                    Console.WriteLine("Rock, Paper, Scissors: (1 = rock, 2 = paper, 3 = scissors)");
                    choice = Console.ReadLine();
                }
            }
        }
コード例 #4
0
        public static Roshambo RPSInput(string userInput)   //Check for valid user input
        {
            Roshambo result = 0;

            string[] acceptedInput = { "r", "p", "s", "rock", "paper", "scissors", "1", "2", "3" };
            while (!acceptedInput.Contains(userInput))
            {
                Console.Write("Please enter valid input. (1)rock, (2)paper, (3) scissors: ");
                userInput = Console.ReadLine().ToLower();
            }
            if (userInput == "r" || userInput == "rock" || userInput == "1")
            {
                result = Roshambo.rock;
            }
            else if (userInput == "p" || userInput == "paper" || userInput == "2")
            {
                result = Roshambo.paper;
            }
            else if (userInput == "s" || userInput == "scissors" || userInput == "3")
            {
                result = Roshambo.scissors;
            }
            return(result);
        }
コード例 #5
0
 public Player(string _name, Roshambo _roshamboValue)
 {
     Name          = _name;
     RoshamboValue = _roshamboValue;
 }
コード例 #6
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to rock, paper, scissors.");
            Console.WriteLine("Please enter name.");
            Player user = new PlayerThree();

            user.Name = Console.ReadLine().ToLower();
            bool again = true;

            while (again)
            {
                Console.WriteLine("Select an opponent: Targaryens or Lannisters. {1 or 2} ");
                Console.WriteLine("\n1.Targaryens.");
                Console.WriteLine("\n2.Lannisters.");

                string enemy   = Console.ReadLine();
                int    hostile = int.Parse(enemy);
                if (hostile == 1)
                {
                    Console.WriteLine("Rock,paper,or scissors? 1-3");
                    PlayerOne opponentOne = new PlayerOne();
                    Roshambo  userChoice  = user.generateRoshambo();
                    Roshambo  npcChoice   = opponentOne.generateRoshambo();
                    string    finalResult = WinOrLose(userChoice, npcChoice);
                    Console.WriteLine($"{user.Name} selected {userChoice}. Targaryens selected {npcChoice}.");
                    if (finalResult == "You're a winner.")
                    {
                        user.Wins++;
                    }
                    else if (finalResult == "You lost.")
                    {
                        user.Losses++;
                    }
                    else if (finalResult == "Tie")
                    {
                        user.Ties++;
                    }
                    Console.WriteLine($"{user.Name}: {userChoice} ");
                    Console.WriteLine($"{opponentOne.Name}: {npcChoice}");
                    Console.WriteLine(finalResult);
                    again = true;
                }
                else if (hostile == 2)
                {
                    Console.WriteLine("Rock,paper,scissors. 1-3");
                    PlayerTwo opponentTwo = new PlayerTwo();
                    Roshambo  userChoice  = user.generateRoshambo();
                    Roshambo  npcChoice   = opponentTwo.generateRoshambo();
                    string    finalResult = WinOrLose(userChoice, npcChoice);
                    Console.WriteLine($"{user.Name} selected {userChoice}. Lannisters selected {npcChoice}.");

                    if (finalResult == "You're a winner.")
                    {
                        user.Wins++;
                    }
                    else if (finalResult == "You lost.")
                    {
                        user.Losses++;
                    }
                    else if (finalResult == "Tie")
                    {
                        user.Ties++;
                    }

                    Console.WriteLine($"{opponentTwo.Name}: {npcChoice}");
                    Console.WriteLine(finalResult);
                    again = true;
                }
                else
                {
                    Console.WriteLine("Please try again, m'lord.");
                    again = true;
                }

                Console.WriteLine("Would you like to go again? y/n");
                string yesNo = Console.ReadLine().ToLower();
                if (yesNo == "yes" || yesNo == "y")
                {
                }
                else if (yesNo == "no" || yesNo == "n")
                {
                    Console.WriteLine("Goodbye.");
                    Console.WriteLine($"You have:\n {user.Wins} Wins\n {user.Losses} Losses\n {user.Ties} Ties");
                    again = false;
                }
            }
        }
コード例 #7
0
        protected Roshambo rpsList; //list rps that only the children of Player can access

        public Player(Roshambo g)   //the constructor is named Player and its parameter is a value from the
        //Roshambo class that it stores in the rpslist variable
        {
            rpsList = g;
        }
コード例 #8
0
 public GrantThompson(Roshambo g) : base(g) //the constructor is Grant Thompson and it takes
     //the value g in the Roshambo class, and stores it in the player varialble rpslist?
 {
     name = "Grant Thompson";
 }
コード例 #9
0
ファイル: player.cs プロジェクト: Dratp/RoShamBo
        public override Roshambo GenerateRoShamBo()
        {
            Roshambo Rock = Roshambo.Rock;

            return(Rock);
        }
コード例 #10
0
 public DwayneJohnson(Roshambo g) : base(g) //the constructor is Dwayne Johnson and it takes
     //the value r in the Roshambo class, and stores it in the player varialble rpslist?
 {
     name = "Dwayne Johnson";
 }