Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace RockPaperScissorApp
- {
- class Program
- {
- static string userChoice = "";
- static string userChoiceInput;
- static string cpuChoice;
- static string rock = "Rock";
- static string paper = "Paper";
- static string scissors = "Scissors";
- static int gameCount = 0;
- static int winCount = 0;
- static int tieCount = 0;
- static void Main(string[] args)
- {
- //Loop to keep the game running
- bool playAgain = true;
- do
- {
- bool inputCorrect = false;
- //Check to see if user input equals Rock, Paper, or Scissors
- do
- {
- Console.Clear();
- Console.Write(@"Please enter ""{0}"", ""{1}"", or ""{2}"" : ", rock, paper, scissors);
- userChoiceInput = Console.ReadLine();
- userChoice = userChoiceInput.First().ToString().ToUpper() + userChoiceInput.Substring(1).ToLower();
- if ((userChoiceInput.Equals(rock, StringComparison.OrdinalIgnoreCase)) ||
- (userChoiceInput.Equals(paper, StringComparison.OrdinalIgnoreCase)) ||
- (userChoiceInput.Equals(scissors, StringComparison.OrdinalIgnoreCase)))
- {
- inputCorrect = true;
- }
- else
- {
- Console.Clear();
- Console.WriteLine("Input Invalid");
- }
- } while (!inputCorrect);
- Console.WriteLine($"You chose {userChoice}");
- //Set Rock, Paper, Scissors array
- string[] cpuChoose = new string[] { "Rock", "Paper", "Scissors" };
- Random rnd = new Random();
- int cpuIndex = rnd.Next(0, 3);
- cpuChoice = cpuChoose[cpuIndex];
- Console.Clear();
- Console.WriteLine("User chooses {0}", userChoice);
- Console.WriteLine("Computer chooses {0}", cpuChoice);
- Play();
- Console.WriteLine("");
- Console.WriteLine($"Game Count: {gameCount}");
- Console.WriteLine($"Wins: { winCount}");
- Console.WriteLine($"Losses: {gameCount - winCount}");
- Console.WriteLine("Win Percent: TODO");
- Console.WriteLine("");
- Console.WriteLine(@"Play Again? Enter ""Y"" or ""N"" ");
- string playAgainInput = Console.ReadLine();
- if(playAgainInput == "N" || playAgainInput =="n")
- {
- playAgain = false;
- }
- } while (playAgain);
- Console.WriteLine("Program Ended");
- }
- //Check to see who wins round
- static void Play()
- {
- if (userChoice == cpuChoice)
- {
- Console.WriteLine("Tie");
- tieCount++;
- }
- else
- {
- if (userChoice == "Rock" && cpuChoice == "Scissors")
- {
- Console.WriteLine("You Win!");
- winCount++;
- }
- if (userChoice == "Rock" && cpuChoice == "Paper")
- {
- Console.WriteLine("You Lose");
- }
- if (userChoice == "Paper" && cpuChoice == "Rock")
- {
- Console.WriteLine("You Win!");
- winCount++;
- }
- if (userChoice == "Paper" && cpuChoice == "Scissors")
- {
- Console.WriteLine("You Lose");
- }
- if (userChoice == "Scissors" && cpuChoice == "Paper")
- {
- Console.WriteLine("You Win!");
- winCount++;
- }
- if (userChoice == "Scissors" && cpuChoice == "Rock")
- {
- Console.WriteLine("You Lose");
- }
- }
- gameCount++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement