Advertisement
Musical_Muze

Rock, Paper, Scissors Console Game in C#

Nov 19th, 2014
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.12 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Rock.Paper.Scissors
  4. {
  5.     class MainClass
  6.     {
  7.         public static void Main (string[] args)
  8.         {
  9.             bool continueOrEnd = true;
  10.             string userChoice;
  11.             string computerChoice;
  12.  
  13.             while (continueOrEnd) {
  14.  
  15.                 //Asks the user for his choice//
  16.                 Console.WriteLine ("MAKE YOUR CHOICE:  ROCK, PAPER, OR SCISSORS?!?");
  17.                 userChoice = (Console.ReadLine ()).ToLower();
  18.  
  19.                 //Generates a random integer and uses this to make the computer's choice//
  20.                 Random rnd = new Random ();
  21.                 int randomNumber = rnd.Next (1, 4);
  22.                 if (randomNumber == 1) {
  23.                     computerChoice = "rock";
  24.                 } else if (randomNumber == 2) {
  25.                     computerChoice = "paper";
  26.                 } else {
  27.                     computerChoice = "scissors";
  28.                 }
  29.  
  30.                 //Presents the player with the computer's choice//
  31.                 Console.WriteLine ("You chose {0}, and the computer chose {1}.", userChoice, computerChoice);
  32.  
  33.                 //Compares the userChoice and computerChoice and proclaims a winner//
  34.                 if (userChoice == computerChoice) {
  35.                     Console.WriteLine ("The result is a tie! Balance has been restored to the Force.");
  36.                 } else {
  37.                     if (userChoice == "rock") {
  38.                         if (computerChoice == "paper") {
  39.                             Console.WriteLine ("Computer wins. Do or do not: there is no try.");
  40.                         } else {
  41.                             Console.WriteLine ("You win! The Force is strong with this one.");
  42.                         }
  43.                     } else if (userChoice == "paper") {
  44.                         if (computerChoice == "scissors") {
  45.                             Console.WriteLine ("Computer wins: I find your lack of skill disturbing.");
  46.                         } else {
  47.                             Console.WriteLine ("Don't get cocky, Kid, but you won.");
  48.                         }
  49.                     } else {
  50.                         if (computerChoice == "rock") {
  51.                             Console.WriteLine ("Computer wins. Use the force next time, Luke.");
  52.                         } else {
  53.                             Console.WriteLine ("You win! We may make a Jedi of you yet.");
  54.                         }
  55.                     }
  56.                 }
  57.                    
  58.                
  59.                 //Asks if the player would like to play again//
  60.                 Console.WriteLine ("Would you like to play again?");
  61.                 userChoice = (Console.ReadLine ()).ToLower();
  62.                 if (userChoice == "yes") {
  63.                     continueOrEnd = true;
  64.                 } else {
  65.                     continueOrEnd = false;
  66.                 }
  67.             }
  68.         }
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement