CSharp - Write program to Play Rock-Scissors-Paper game

Requirements

You will write a program that plays a specified number of rounds of the rock-scissors-paper game with the user.

Scoring one point for a victory and half a point for a tie.

Hint

The computer "chooses" using random numbers: 1 for rock, 2 for scissors, and 3 for paper.

When the user enters something other than R, S, or P, you take it as "paper."

Do not distinguish between lowercase and uppercase in user input.

Demo

using System;
class Program{//from ww w .  j  av  a 2s. c o m
    static void Main(string[] args){
        // Preparations 
        Random randomNumbers = new Random();

        double playerPoints = 0;
        double computerPoints = 0;

        int rock = 1, scissors = 2, paper = 3;

        // Inputs 
        Console.Write("Enter your name: ");
        string playerName = Console.ReadLine();

        Console.Write("Enter number of game rounds: ");
        string input = Console.ReadLine();
        int totalRounds = Convert.ToInt32(input);

        Console.WriteLine();

        // Individual rounds 
        for (int roundNumber = 0; roundNumber < totalRounds; roundNumber++)
        {
            // Computer chooses 
            int computerChoice = randomNumbers.Next(1, 3 + 1);

            // Player chooses 
            Console.Write("Enter R or S or P: ");
            string playerInput = Console.ReadLine();
            string playerInputUppercase = playerInput.ToUpper();
            int playerChoice = playerInputUppercase == "R" ?
                rock : (playerInputUppercase == "S" ? scissors : paper);

            // Round evaluation 
            string message = "";
            if (computerChoice == rock && playerChoice == scissors ||
                computerChoice == scissors && playerChoice == paper ||
                computerChoice == paper && playerChoice == rock)
            {
                // Computer won 
                computerPoints += 1;
                message = "I won";
            }
            else
            {
                // Tie or player won 
                if (computerChoice == playerChoice)
                {
                    // Tie 
                    computerPoints += 0.5;
                    playerPoints += 0.5;
                    message = "Tie";
                }else{// Player won 
                    playerPoints += 1;
                    message = "You won";
                }
            } 
            string playerChoiceInText = playerChoice == rock ? "Rock" : (playerChoice == scissors ? "Scissors" : "Paper");
            string computerChoiceInText = computerChoice == rock ? "Rock" : (computerChoice == scissors ? "Scissors" : "Paper");
            Console.WriteLine(playerName + ":Computer - " + playerChoiceInText + ":" + computerChoiceInText);
            Console.WriteLine(message);
        }
        Console.WriteLine(playerName + ":Computer - " + playerPoints.ToString() + ":" + computerPoints.ToString());

    }
}

Result