Example #1
0
        public static Card[,] GetShuffledCards(int num)
        {
            _deck = new Card[num, num];
            int  pairsOfCards = (num * num) / 2;
            int  counter      = 1;
            bool isUpToMiddle = true;

            for (int x = 0; x < num; x++)
            {
                for (int y = 0; y < num; y++)
                {
                    if (counter <= pairsOfCards && isUpToMiddle)
                    {
                        _deck[x, y] = new Card(counter++);
                        if (_deck[x, y].Value.Equals(pairsOfCards))
                        {
                            isUpToMiddle = false;
                        }
                    }
                    else
                    {
                        _deck[x, y] = new Card(--counter);
                    }
                }
            }

            _deck.Shuffle();

            return(_deck);
        }
Example #2
0
        public void StartNewSession()
        {
            selectedCards.Clear();
            won = false;
            IEnumerator <string> cardColors  = CardColors();
            IEnumerator <int>    cardNumbers = CardNumbers();

            for (int y = 0; y < cards.GetLength(1); y++)
            {
                for (int x = 0; x < cards.GetLength(0); x++)
                {
                    cardColors.MoveNext();
                    cardNumbers.MoveNext();

                    cards[x, y] = new Card(
                        cardColors.Current,
                        cardNumbers.Current.ToString());

                    cards[x, y].Clicked += OnCardClicked;
                }
            }

            cards.Shuffle();
        }