Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

MUST BE DONE IN CSHARP AS A CONSOLE APPLICATION Create a Rock-Paper-Scissors App

ID: 3793900 • Letter: M

Question

MUST BE DONE IN CSHARP AS A CONSOLE APPLICATION

Create a Rock-Paper-Scissors Application

Create a Class to contain the game data and any input or output methods. The main method should contain no Console methods, all functionality should be contained within the class.

The program will ask the user’s name, and the number of matches to play. This input needs to be validated as an odd number (in order to avoid ties), with a maximum value of 9.

The individual match results should be stored in an array.

The program will then prompt the user to choose rock, paper or scissors. It will generate a random value for the computer and declare a winner. In the case of a tie, that match will repeat until a winner is found.

After the number of matches specified above the program will provide a game summary for each match and the overall winner. For instance:

Match 1 (Player won) Rocks vs Scissors [after 3 ties] Match 2 (Computer won)…. Match 3 (Player won)… Overall winner: Player! Congratulations!

Explanation / Answer

class Program

{

    static void Main(string[] args)

    {

        Game rps = new Game();

        rps.printHeader();

        rps.gameStart();

    }

}

class GameDetails

{

    public string Name;

    public int game;

    public GameDetails()

    {

        Name = "unknown";

        game = 0;

    }

}

class Game

{

    string name;

    int numPlays;

    int game;

    GameDetails[] gameArray;

    public int NumGames

    {

        get

        {

            return numPlays;

        }

        set

        {

            numPlays = value;

        }

    }

    public void printHeader()

    {

        Console.WriteLine("Welcome to rock, paper, scissors");

        this.userSettings();

    }

    private void InitializeArrays()

    {

        gameArray = new GameDetails[game];

        for (int game = 0; game < numPlays; game++)

        {

            gameArray[game] = new GameDetails();

        }

    }

    public void userSettings()

    {

        Console.WriteLine("What is your name: ");

        name = Console.ReadLine();

        Console.WriteLine("How many games would you like to play?: ");

        Int32.TryParse(Console.ReadLine(), out numPlays);

        while (numPlays >9 && numPlays % 2 == 0)

        {

            Console.WriteLine(" Number is not odd try again.");

            Console.WriteLine("How many games would you like to play?: ");

            Int32.TryParse(Console.ReadLine(), out numPlays);

        }

    }

    public void gameStart()

    {

        for (game = 1; game <= numPlays; game++)

            Console.WriteLine("Please choose Rock, Paper, or Scissors");

        string userSelection = Console.ReadLine();

        Random r = new Random();

        int computerSelection = r.Next(4);

        if (computerSelection == 1)

        {

            if (userSelection == "rock")

            {

                Console.WriteLine("Computer Choice: Rock ");

                Console.WriteLine("Game [{0}] is a tie", game);

            }

            else if (userSelection == "paper")

            {

                Console.WriteLine("Computer Choice: Paper ");

                Console.WriteLine("Game[{ 0}] is a tie", game);

            }

            else if (userSelection == "scissors")

            {

                Console.WriteLine("Computer Choice: Scissors ");

                Console.WriteLine("Game [{0}] is a tie", game);

            }

            else

            {

                Console.WriteLine("You must choose either rock, paper or scissors");

            }

        }

        else if (computerSelection == 2)

        {

            if (userSelection == "rock")

            {

                Console.WriteLine("Computer Choice: Paper ");

                Console.WriteLine("You lose game [{0}], papaer beats rock", game);

            }

            else if (userSelection == "paper")

            {

                Console.WriteLine("Computer Choice: Scissors ");

                Console.WriteLine("You lose game [{0}], scissors beats paper", game);

            }

            else if (userSelection == "scissors")

            {

                Console.WriteLine("Computer Choice: Rock ");

                Console.WriteLine("You lose game [{0}], Rock beats scissors", game);

            }

            else

            {

                Console.WriteLine("You must choose either rock, paper or scissors");

            }

        }

        else if (computerSelection == 3)

        {

            if (userSelection == "rock")

            {

                Console.WriteLine("The computer chose scissors");

                Console.WriteLine("You win game [{0}], rock beats scissors", game);

            }

            else if (userSelection == "paper")

            {

                Console.WriteLine("The computer chose rock");

                Console.WriteLine("You win game [{0}],paper beats rock", game);

            }

            else if (userSelection == "scissors")

            {

                Console.WriteLine("The computer chose paper");

                Console.WriteLine("You win game [{0}], scissors beats paper!", game);

            }

            else

            {

                Console.WriteLine("You must choose either rock, paper or scissors");

            }

            Console.ReadLine();

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote