Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

randomise array for "match" card game problem

$
0
0
hi all ok so i trying to make a match card game , the rules i am given are

36 cars 9 sets of 4 ranging from 2 - 10 , now i have looked at two ways of doing this as below shows

int[,] cards = new int[9,4]



and

int[] cards = new int[36]



but then when i use the bottom one and then have to shuffle the deck this is the code i am using but what i want to do is check if the random number generated has already been used then a bool varibale available equals false and if it is true then i declare in the new array the card and value from the original cards array

 int shufflecount = 0;

            do
            {
                int RNum = r.Next(0, 36);
                for (int i = 0; i <= shufflecount; i++)
                {
                    if (shuffledcards[i] == RNum)
                    {
                        available = false;
                    }

                }
                if (available == true)
                {
                    shuffledcards[shufflecount] =RNum;
                    shufflecount++;
                }
                if (shufflecount == 20)
                { count++; }
            } while (shufflecount != 36);



but what this is doing is comparing the actual value inside the array with the random number and i need it to check if the random number matches the array index

any pointers or advice please? i know in next chapter it gives me a more mathematical way of doing this but for now i have to make a basic way with the if staetments for checking if its been used etc so please try dumb it down :)

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>