Guest User

Rock, Paper, Scissors

a guest
Jan 2nd, 2020
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.51 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.         private static int playerPoints = 0;
  12.         private static int computerPoints = 0;
  13.         private static Dictionary<string, int> handsValues = new Dictionary<string, int>()
  14.             {
  15.                 {"Rock", 0},
  16.                 {"Paper", 1},
  17.                 {"Sci", 2}
  18.             };
  19.         static void Main(string[] args)
  20.         {
  21.             Console.Write("How many rounds do you want to play ? : ");
  22.             int numberOfRounds = Convert.ToInt32(Console.ReadLine());
  23.  
  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\r\n");
  37.                 }
  38.                 else
  39.                 {
  40.                     DeeperCheck(handsValues[playerHand], computerHand);
  41.                 }
  42.             }
  43.  
  44.             Console.WriteLine("*** RESULTS ***");
  45.             Console.WriteLine("Player Points : " + playerPoints);
  46.             Console.WriteLine("Computer Points : " + computerPoints);
  47.  
  48.             if (playerPoints < computerPoints)
  49.             {
  50.                 Console.WriteLine("Computer Wins");
  51.             }
  52.             else if (playerPoints > computerPoints)
  53.             {
  54.                 Console.WriteLine("Player Wins");
  55.             }
  56.             else
  57.             {
  58.                 Console.WriteLine("Equal None Win");
  59.             }
  60.  
  61.             Console.ReadLine();
  62.         }
  63.  
  64.         private static void DeeperCheck(int playerHand, int computerHand)
  65.         {
  66.             switch (playerHand)
  67.             {
  68.                 case 0:
  69.                     if (computerHand == 1)
  70.                     {
  71.                         computerPoints++;
  72.                         Console.WriteLine("Computer wins a point\r\n");
  73.                     }
  74.                     else
  75.                     {
  76.                         playerPoints++;
  77.                         Console.WriteLine("Player wins a point\r\n");
  78.                     }
  79.                     break;
  80.  
  81.                 case 1:
  82.                     if (computerHand == 2)
  83.                     {
  84.                         computerPoints++;
  85.                         Console.WriteLine("Computer wins a point\r\n");
  86.                     }
  87.                     else
  88.                     {
  89.                         playerPoints++;
  90.                         Console.WriteLine("Player wins a point\r\n");
  91.                     }
  92.                     break;
  93.  
  94.                 case 2:
  95.                     if (computerHand == 0)
  96.                     {
  97.                         computerPoints++;
  98.                         Console.WriteLine("Computer wins a point\r\n");
  99.                     }
  100.                     else
  101.                     {
  102.                         playerPoints++;
  103.                         Console.WriteLine("Player wins a point\r\n");
  104.                     }
  105.                     break;
  106.             }
  107.         }
  108.     }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment