Пример #1
0
 public Form1()
 {
     InitializeComponent();
     Display.ReadOnly = true;
     game             = new RPS();
     Display.Text     = "Player Wins: " + game.tally[0] + "\tCPU Wins: " + game.tally[1];
 }
Пример #2
0
        public override RPS GenerateRPS()
        {
            var random     = new Random();
            RPS randomEnum = (RPS)random.Next(0, 3);

            return(randomEnum);
        }
Пример #3
0
        static void Main(string[] args)
        {
            do
            {
                Console.WriteLine($"Human player registers a {RPS.PlayOneGame()}");
                Console.WriteLine();
            } while (RPS.Continue());

            Console.WriteLine("Record of wins, losses, and draws:");
            RPS.PrintResults();

            RPS.PrintHistory();
        }
Пример #4
0
 private void UserSelected(RPS option)
 {
     yourSelection       = option;
     pictureBoxYou.Image = rpsPicture[option];
     panelRPS.Enabled    = false;
     if (socketClient != null)
     {
         socketClient.Send(BitConverter.GetBytes((int)option));
         Result();
     }
     else
     {
         MessageBox.Show("Connection Failed!");
     }
 }
Пример #5
0
 static bool userWon(RPS playerOne, RPS playerTwo)
 {
     if (playerOne == RPS.r && playerTwo == RPS.p)
     {
         return(true);
     }
     else if ((playerOne == RPS.r && playerTwo == RPS.p) || playerOne == playerTwo)
     {
         return(false);
     }
     else
     {
         return(playerOne < playerTwo);
     }
 }
Пример #6
0
        public static void Main()
        {
            Console.WriteLine("Please choose Rock, Paper, or Scissors!");
            string playerInput = Console.ReadLine();
            string playerPlay  = playerInput.ToLower();

            Console.WriteLine("You played: {0}", playerPlay);
            RPS    game    = new RPS();
            string cpuPlay = game.generateCpuPlay();

            Console.WriteLine("The cpu played: {0}", cpuPlay);

            RPS gameOutcome = new RPS();

            gameOutcome.comparePlays(cpuPlay, playerPlay);
        }
Пример #7
0
        static void Main(string[] args)
        {
            Random RNG = new Random();
            RPS    playerOne = (RPS)RNG.Next(0, 3), playerTwo;

            Console.Write("Pick a character (r,p,s): ");
            if (!Enum.TryParse(Console.ReadLine(), out playerTwo))
            {
                playerTwo = (RPS)RNG.Next(0, 3);
            }
            string finalMessage = string.Format("The computer picked: {0}, you picked: {1}.", ((rockPS)playerOne).ToString(), ((rockPS)playerTwo).ToString());

            if (userWon(playerOne, playerTwo))
            {
                finalMessage += " You won!";
            }
            else
            {
                finalMessage += " You didn't win!";
            }
            Console.WriteLine(finalMessage);
        }
Пример #8
0
        static async Task Main(string[] args)
        {
            RPS rps = new RPS();

            string player1Name   = "";
            string player2Name   = "";
            string player1Choice = "";

            string opponentOption = "";

            string playAgain = "yes";

            Dictionary <string, string> postDict = new Dictionary <string, string>();

            var urlPlayer = "http://localhost/RPS/index.php?id=playersave";
            var urlMatch  = "http://localhost/RPS/index.php?id=matchsave";

            using var client = new HttpClient();

            FormUrlEncodedContent content;
            HttpResponseMessage   response;
            string responseString;

            while (playAgain == "yes")
            {
                rps.choiceCount.Add("rock", 0);
                rps.choiceCount.Add("paper", 0);
                rps.choiceCount.Add("scissors", 0);

                Console.WriteLine("Please enter your name:\n");
                player1Name = Console.ReadLine();
                postDict.Add("player1", player1Name);
                Console.WriteLine("Welcome " + player1Name + " to Rock Paper Scissors!\n");
                Console.WriteLine("Please enter an option; 1 (to play against another player), 2 (to play me... if you dare...)\n");
                opponentOption = Console.ReadLine().Trim();

                if (opponentOption == "1")
                {
                    string player2Choice = "";

                    Console.WriteLine("\nWise choice " + player1Name + "\n");
                    Console.WriteLine("Please enter your opponents name:\n");
                    player2Name = Console.ReadLine();

                    while (postDict.ContainsValue(player2Name))
                    {
                        Console.WriteLine("That name has already been taken!\n");
                        Console.WriteLine("Please enter your opponents name:\n");
                        player2Name = Console.ReadLine();
                    }

                    postDict.Add("player2", player2Name);

                    content  = new FormUrlEncodedContent(postDict);
                    response = await client.PostAsync(urlPlayer, content);

                    responseString = await response.Content.ReadAsStringAsync();

                    Console.WriteLine("\nWelcome " + player2Name + " to a best of 3 match of Rock Paper Scissors against " + player1Name + "\n");

                    while (rps.player1Score < 3 && rps.player2Score < 3)
                    {
                        rps.matchCounter++;
                        Console.WriteLine("Match: " + rps.matchCounter + "\n");
                        Console.WriteLine(player1Name + ", make your choice:\n");
                        player1Choice = Console.ReadLine().ToLower().Trim();

                        while (!rps.isValidChoice(player1Choice))
                        {
                            Console.WriteLine("Invalid choice! " + player1Name + ", make your choice:\n");
                            player1Choice = Console.ReadLine().ToLower().Trim();
                        }

                        Console.WriteLine(player2Name + ", make your choice:\n");
                        player2Choice = Console.ReadLine().ToLower().Trim();

                        while (!rps.isValidChoice(player2Choice))
                        {
                            Console.WriteLine("Invalid choice! " + player2Name + ", make your choice:\n");
                            player2Choice = Console.ReadLine().ToLower().Trim();
                        }
                        rps.fight(player1Choice, player2Choice, player1Name, player2Name);
                    }

                    Console.WriteLine("Would you like to play again? (yes/no)\n");
                    playAgain = Console.ReadLine();

                    while (!playAgain.Equals("yes") && !playAgain.Equals("no"))
                    {
                        Console.WriteLine("That isn't an option! Please enter 'yes' or 'no'\n");
                        playAgain = Console.ReadLine();
                    }
                }
                else if (opponentOption == "2")
                {
                    Console.WriteLine("\nYou fool! I will destroy you!\n");
                    Console.WriteLine("This is a best of 3 match of Rock Paper Scissors, you against me\n");

                    player2Name = "Computer";

                    content  = new FormUrlEncodedContent(postDict);
                    response = await client.PostAsync(urlPlayer, content);

                    responseString = await response.Content.ReadAsStringAsync();

                    while (rps.player1Score < 3 && rps.player2Score < 3)
                    {
                        rps.matchCounter++;
                        Console.WriteLine("Match: " + rps.matchCounter + "\n");
                        Console.WriteLine(player1Name + ", make your choice:\n");
                        player1Choice = Console.ReadLine().ToLower().Trim();

                        while (!rps.isValidChoice(player1Choice))
                        {
                            Console.WriteLine("Invalid choice! " + player1Name + ", make your choice:\n");
                            player1Choice = Console.ReadLine().ToLower().Trim();
                        }

                        Random   rdm             = new Random();
                        var      random          = rdm.Next(0, 3);
                        string[] computerChoices = { "rock", "paper", "scissors" };
                        string   computerChoice  = computerChoices[random];

                        rps.fight(player1Choice, computerChoice, player1Name, player2Name);
                    }

                    if (rps.player1Score == 3)
                    {
                        Console.WriteLine("NOOOO.... I will have my revenge!\n");
                    }
                    else
                    {
                        Console.WriteLine("HA! Too easy.\n");
                    }

                    Console.WriteLine("Would you like to play again? (yes/no)\n");
                    playAgain = Console.ReadLine();

                    while (!playAgain.Equals("yes") && !playAgain.Equals("no"))
                    {
                        Console.WriteLine("That isn't an option! Please enter 'yes' or 'no'\n");
                        playAgain = Console.ReadLine();
                    }
                }
                else
                {
                    Console.WriteLine("That wasn't an option!\n");
                }

                if (opponentOption == "1" || opponentOption == "2")
                {
                    postDict.Clear();
                    postDict.Add("player1", player1Name);
                    postDict.Add("player2", player2Name);
                    postDict.Add("player1Score", rps.player1Score.ToString());
                    postDict.Add("player2Score", rps.player2Score.ToString());
                    postDict.Add("mostCommonChoice", "Rock: " + rps.choiceCount["rock"] + ", Paper: " + rps.choiceCount["paper"] + ", Scissors: " + rps.choiceCount["scissors"]);

                    content  = new FormUrlEncodedContent(postDict);
                    response = await client.PostAsync(urlMatch, content);

                    responseString = await response.Content.ReadAsStringAsync();
                }

                rps.matchCounter = 0;
                rps.player1Score = 0;
                rps.player2Score = 0;
                rps.choiceCount.Clear();
                postDict.Clear();
            }

            Console.WriteLine("Thank you for playing. Goodbye.\n");
        }
Пример #9
0
 private void Form1_Load(object sender, EventArgs e)
 {
     game = new RPS();
 }
Пример #10
0
        public void Play()
        {
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine("Welcome to the RPS Championships!" + "\n");
            Console.ResetColor();

            HumanPlayer human = new HumanPlayer();

            Console.ForegroundColor = ConsoleColor.DarkCyan;
            Console.Write("Enter your name: ");
            human.Name = Console.ReadLine();

            do
            {
                Player opponent = GetPlayer();

                RPS humanChoice  = human.GenerateRPS();
                RPS playerChoice = opponent.GenerateRPS();

                Console.WriteLine($"You chose: {humanChoice}");
                Console.WriteLine($"Opponent chose: {playerChoice}");

                if (humanChoice == RPS.Rock && playerChoice == RPS.Rock)
                {
                    Console.WriteLine("Draw!");
                }
                else if (humanChoice == RPS.Paper && playerChoice == RPS.Paper)
                {
                    Console.WriteLine("Draw!");
                }
                else if (humanChoice == RPS.Scissors && playerChoice == RPS.Scissors)
                {
                    Console.WriteLine("Draw!");
                }
                else if (humanChoice == RPS.Paper && playerChoice == RPS.Rock)
                {
                    Console.WriteLine("You win!");
                    HumanScore++;
                }
                else if (humanChoice == RPS.Scissors && playerChoice == RPS.Paper)
                {
                    Console.WriteLine("You win!");
                    HumanScore++;
                }
                else if (humanChoice == RPS.Rock && playerChoice == RPS.Scissors)
                {
                    Console.WriteLine("You win!");
                    HumanScore++;
                }
                else if (humanChoice == RPS.Rock && playerChoice == RPS.Paper)
                {
                    Console.WriteLine("You lose!");
                    OpponentScore++;
                }
                else if (humanChoice == RPS.Paper && playerChoice == RPS.Scissors)
                {
                    Console.WriteLine("You lose!");
                    OpponentScore++;
                }
                else if (humanChoice == RPS.Scissors && playerChoice == RPS.Rock)
                {
                    Console.WriteLine("You lose!");
                    OpponentScore++;
                }



                Console.WriteLine($"Your score: {HumanScore}");
                Console.WriteLine($"Opponent score: {OpponentScore}");
            } while (PlayAgain());
        }