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 AnswerRockPaperScissors
- {
- class Program
- {
- static void Main(string[] args)
- {
- Dictionary<string, int> handsValues = new Dictionary<string, int>()
- {
- {"Rock", 0},
- {"Paper", 1},
- {"Sci", 2}
- };
- Console.Write("How many rounds do you want to play ? : ");
- int numberOfRounds = Convert.ToInt32(Console.ReadLine());
- int playerPoints = 0;
- int computerPoints = 0;
- Random rnd = new Random();
- for (int counter = 1; counter <= numberOfRounds; counter++)
- {
- Console.Write("Player Hand : ");
- string playerHand = Console.ReadLine();
- int computerHand = rnd.Next(0, 3);
- Console.WriteLine("Computer Hand : " + handsValues.Keys.ElementAt(computerHand));
- if (handsValues[playerHand] == computerHand)
- {
- playerPoints++;
- computerPoints++;
- Console.WriteLine("Player And Computer Win a Point" + Environment.NewLine);
- }
- else
- {
- switch (handsValues[playerHand])
- {
- case 0:
- if (computerHand == 1)
- {
- computerPoints++;
- Console.WriteLine("Computer wins a point" + Environment.NewLine);
- }
- else
- {
- playerPoints++;
- Console.WriteLine("Player wins a point" + Environment.NewLine);
- }
- break;
- case 1:
- if (computerHand == 2)
- {
- computerPoints++;
- Console.WriteLine("Computer wins a point" + Environment.NewLine);
- }
- else
- {
- playerPoints++;
- Console.WriteLine("Player wins a point" + Environment.NewLine);
- }
- break;
- case 2:
- if (computerHand == 0)
- {
- computerPoints++;
- Console.WriteLine("Computer wins a point" + Environment.NewLine);
- }
- else
- {
- playerPoints++;
- Console.WriteLine("Player wins a point" + Environment.NewLine);
- }
- break;
- }
- }
- }
- Console.WriteLine("*** RESULTS ***");
- Console.WriteLine("Player Points : " + playerPoints);
- Console.WriteLine("Computer Points : " + computerPoints);
- if (playerPoints < computerPoints)
- {
- Console.WriteLine("Computer Wins");
- }
- else if (playerPoints > computerPoints)
- {
- Console.WriteLine("Player Wins");
- }
- else
- {
- Console.WriteLine("Equal None Win");
- }
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement