Advertisement
jyoung12387

Rock Paper Scissors v1.0

Feb 29th, 2020
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.32 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace RockPaperScissorApp
  8. {
  9.     class Program
  10.     {
  11.         static string userChoice = "";
  12.         static string userChoiceInput;
  13.         static string cpuChoice;
  14.         static string rock = "Rock";
  15.         static string paper = "Paper";
  16.         static string scissors = "Scissors";
  17.         static int gameCount = 0;
  18.         static int winCount = 0;
  19.         static int tieCount = 0;
  20.  
  21.         static void Main(string[] args)
  22.         {
  23.             //Loop to keep the game running
  24.             bool playAgain = true;
  25.             do
  26.             {
  27.                 bool inputCorrect = false;
  28.                 //Check to see if user input equals Rock, Paper, or Scissors
  29.                 do
  30.                 {
  31.                     Console.Clear();
  32.                     Console.Write(@"Please enter ""{0}"", ""{1}"", or ""{2}"" : ", rock, paper, scissors);
  33.                     userChoiceInput = Console.ReadLine();
  34.                     userChoice = userChoiceInput.First().ToString().ToUpper() + userChoiceInput.Substring(1).ToLower();
  35.  
  36.                     if ((userChoiceInput.Equals(rock, StringComparison.OrdinalIgnoreCase)) ||
  37.                     (userChoiceInput.Equals(paper, StringComparison.OrdinalIgnoreCase)) ||
  38.                     (userChoiceInput.Equals(scissors, StringComparison.OrdinalIgnoreCase)))
  39.                     {
  40.                         inputCorrect = true;
  41.                     }
  42.                     else
  43.                     {
  44.                         Console.Clear();
  45.                         Console.WriteLine("Input Invalid");
  46.                     }
  47.                 } while (!inputCorrect);
  48.  
  49.                 Console.WriteLine($"You chose {userChoice}");
  50.  
  51.                 //Set Rock, Paper, Scissors array
  52.                 string[] cpuChoose = new string[] { "Rock", "Paper", "Scissors" };
  53.  
  54.                 Random rnd = new Random();
  55.                 int cpuIndex = rnd.Next(0, 3);
  56.                 cpuChoice = cpuChoose[cpuIndex];
  57.  
  58.                 Console.Clear();
  59.                 Console.WriteLine("User chooses {0}", userChoice);
  60.                 Console.WriteLine("Computer chooses {0}", cpuChoice);
  61.                 Play();
  62.                 Console.WriteLine("");
  63.                 Console.WriteLine($"Game Count: {gameCount}");
  64.                 Console.WriteLine($"Wins: { winCount}");
  65.                 Console.WriteLine($"Losses: {gameCount - winCount}");
  66.                 Console.WriteLine("Win Percent: TODO");
  67.  
  68.                 Console.WriteLine("");
  69.                 Console.WriteLine(@"Play Again? Enter ""Y"" or ""N"" ");
  70.                 string playAgainInput = Console.ReadLine();
  71.  
  72.                 if(playAgainInput == "N" || playAgainInput =="n")
  73.                 {
  74.                     playAgain = false;
  75.                 }
  76.  
  77.             } while (playAgain);
  78.  
  79.          Console.WriteLine("Program Ended");
  80.            
  81.         }
  82.        
  83.         //Check to see who wins round
  84.         static void Play()
  85.         {
  86.             if (userChoice == cpuChoice)
  87.             {
  88.                 Console.WriteLine("Tie");
  89.                 tieCount++;
  90.             }
  91.             else
  92.             {
  93.                 if (userChoice == "Rock" && cpuChoice == "Scissors")
  94.                 {
  95.                     Console.WriteLine("You Win!");
  96.                     winCount++;
  97.                 }
  98.                 if (userChoice == "Rock" && cpuChoice == "Paper")
  99.                 {
  100.                     Console.WriteLine("You Lose");
  101.                 }
  102.                 if (userChoice == "Paper" && cpuChoice == "Rock")
  103.                 {
  104.                     Console.WriteLine("You Win!");
  105.                     winCount++;
  106.                 }
  107.                 if (userChoice == "Paper" && cpuChoice == "Scissors")
  108.                 {
  109.                     Console.WriteLine("You Lose");
  110.                 }
  111.                 if (userChoice == "Scissors" && cpuChoice == "Paper")
  112.                 {
  113.                     Console.WriteLine("You Win!");
  114.                     winCount++;
  115.                 }
  116.                 if (userChoice == "Scissors" && cpuChoice == "Rock")
  117.                 {
  118.                     Console.WriteLine("You Lose");
  119.                 }
  120.             }
  121.             gameCount++;
  122.         }
  123.  
  124.     }
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement