Advertisement
Guest User

Rock, Paper, Scissors

a guest
Jan 3rd, 2020
338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.75 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 AnswerRockPaperScissors
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Dictionary<string, int> handsValues = new Dictionary<string, int>()
  14.             {
  15.                 {"Rock", 0},
  16.                 {"Paper", 1},
  17.                 {"Sci", 2}
  18.             };
  19.  
  20.             Console.Write("How many rounds do you want to play ? : ");
  21.             int numberOfRounds = Convert.ToInt32(Console.ReadLine());
  22.             int playerPoints = 0;
  23.             int computerPoints = 0;
  24.             Random rnd = new Random();
  25.  
  26.             for (int counter = 1; counter <= numberOfRounds; counter++)
  27.             {
  28.                 Console.Write("Player Hand : ");
  29.                 string playerHand = Console.ReadLine();
  30.                 int computerHand = rnd.Next(0, 3);
  31.                 Console.WriteLine("Computer Hand : " + handsValues.Keys.ElementAt(computerHand));
  32.                 if (handsValues[playerHand] == computerHand)
  33.                 {
  34.                     playerPoints++;
  35.                     computerPoints++;
  36.                     Console.WriteLine("Player And Computer Win a Point" + Environment.NewLine);
  37.                 }
  38.                 else
  39.                 {
  40.                     switch (handsValues[playerHand])
  41.                     {
  42.                         case 0:
  43.                             if (computerHand == 1)
  44.                             {
  45.                                 computerPoints++;
  46.                                 Console.WriteLine("Computer wins a point" + Environment.NewLine);
  47.                             }
  48.                             else
  49.                             {
  50.                                 playerPoints++;
  51.                                 Console.WriteLine("Player wins a point" + Environment.NewLine);
  52.                             }
  53.                             break;
  54.  
  55.                         case 1:
  56.                             if (computerHand == 2)
  57.                             {
  58.                                 computerPoints++;
  59.                                 Console.WriteLine("Computer wins a point" + Environment.NewLine);
  60.                             }
  61.                             else
  62.                             {
  63.                                 playerPoints++;
  64.                                 Console.WriteLine("Player wins a point" + Environment.NewLine);
  65.                             }
  66.                             break;
  67.  
  68.                         case 2:
  69.                             if (computerHand == 0)
  70.                             {
  71.                                 computerPoints++;
  72.                                 Console.WriteLine("Computer wins a point" + Environment.NewLine);
  73.                             }
  74.                             else
  75.                             {
  76.                                 playerPoints++;
  77.                                 Console.WriteLine("Player wins a point" + Environment.NewLine);
  78.                             }
  79.                             break;
  80.                     }
  81.                 }
  82.             }
  83.  
  84.             Console.WriteLine("*** RESULTS ***");
  85.             Console.WriteLine("Player Points : " + playerPoints);
  86.             Console.WriteLine("Computer Points : " + computerPoints);
  87.  
  88.             if (playerPoints < computerPoints)
  89.             {
  90.                 Console.WriteLine("Computer Wins");
  91.             }
  92.             else if (playerPoints > computerPoints)
  93.             {
  94.                 Console.WriteLine("Player Wins");
  95.             }
  96.             else
  97.             {
  98.                 Console.WriteLine("Equal None Win");
  99.             }
  100.  
  101.             Console.ReadLine();
  102.         }
  103.     }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement