Quantcast
Channel: Dice Roll Game help
Viewing all articles
Browse latest Browse all 3

Dice Roll Game help

0
0
So I am making a dice roll game but my random number generator does not repeat numbers. Please Help I cant seem to get it

static void Main(string[] args)
        {
            playerInfo player = new playerInfo();
            Console.WriteLine("Enter the amount of dice you want to play with");
            Console.WriteLine("Can only use 1-6 dies");
            int dice = Int32.Parse(Console.ReadLine());
            int players = 2;
            int[,] playerArray = new int [players, dice];

            Random rnd = new Random();
            int[] diceRoll = new int[6] { 1, 2, 3, 4, 5, 6};

            int count = 0;

            for (int i = 0; i < players; i++)
            {

                count++;

                for (int d = 0; d < dice; d++)
                {
                    int randomIndex = rnd.Next(0,6);
                    int temp = diceRoll[randomIndex];
                    diceRoll[randomIndex] = diceRoll[d];
                    diceRoll[d] = temp;
                }

                int sum = 0;
                for (int y = 0; y < dice; y++)
                {
                    sum += diceRoll[y];
                }

                Console.WriteLine("\n");
                Console.WriteLine("Input name of player #{0}:", count);
                player.MyName = Console.ReadLine();
                Console.WriteLine("\n");

                for (int x = 0; x < dice; ++x)
                    Console.WriteLine(diceRoll[x]);

                Console.WriteLine("\n");
                Console.WriteLine("Your Score is: {0}",  sum);
            }
            Console.ReadLine();
        }

        class playerInfo
        {
            public string MyName { get; set; }
            public int score { get; set; }
        }


Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles





Latest Images