dimanche 26 janvier 2020

How to randomize variables from arrays in a rock, paper, scissors game in C#? [duplicate]

I am making a rock, paper, scissors game. I am using an array to the three variables and am trying to randomize the outcome and compare the random string to the user input. I have tried many methods with the random function and the one in the code makes the most sense to me, but it doesn't work. I am trying to make this code as concise as possible. I have seen other ways of creating this game, but they seem inefficient to me. I believe sticking with an array will allow my code to shorten and run faster. Please help me out and guide me on the right direction, thank you.

 using System;

namespace ConsoleApp1
{


    class MyArray
    {




        static void Main(string[] args)
        {

            var array = new string[] { "rock", "paper", "scissors" };
            var array = new Random();


            Console.WriteLine("Rock, paper, or scissors?");
            string rps = Console.ReadLine();

            switch (rps)
            {
                case "Rock":
                //??
                    break;
                case "Paper":
                //??
                    break;
                case "Scissors":
                //??
                    break;
            }

        }
        }
}



Aucun commentaire:

Enregistrer un commentaire