public MatchingGameViewModel(CardDeck selectedDeck, bool isMatchingGame, int[] cardsOrder, bool[] cardsUseDuplicate, bool[] cardsIsMatched, bool[] cardsIsSelected) : this(selectedDeck, isMatchingGame, false) { // add card pair according to original cards order for (int i = 0; i < cardsOrder.Length; ++i) { CardPair cardPair = selectedDeck.Collection[cardsOrder[i]]; if (cardsUseDuplicate[i]) { cardPair = cardPair.Duplicate(); } cardPair.IsMatchingGame = isMatchingGame; cardPair.IsMatched = cardsIsMatched[i]; cardPair.IsLoaded = true; //cardPair.IsSelected = cardsIsSelected[i]; cardPair.SelectionChanged += new EventHandler(card_SelectionChanged); CardPairs.Add(cardPair); } SetRowsAndColumns(); Matches = cardsIsMatched.Count(isMatched => isMatched) / 2; }
private void SlowCollectionAdd(List <CardPair> cardpairs) { List <CardPair> temp = new List <CardPair>(); foreach (CardPair cpair in cardpairs) { cpair.IsSelected = false; CardPair dup = cpair.Duplicate(); if (IsMatchingGame) { dup.IsMatchingGame = true; cpair.IsMatchingGame = true; } else { dup.IsMatchingGame = false; cpair.IsMatchingGame = false; } cpair.IsLoaded = false; dup.IsLoaded = false; cpair.IsMatched = false; dup.IsMatched = false; temp.Add(cpair); temp.Add(dup); } cardpairs = Randomize <CardPair>(temp); List <int> indexCollection = new List <int>(); int i = 0; foreach (CardPair cp in cardpairs) { CardPairs.Add(cp); cp.SelectionChanged += new EventHandler(card_SelectionChanged); indexCollection.Add(i++); } //Randomize the IndexCollection indexCollection = Randomize <int>(indexCollection); DispatcherTimer _timer = new DispatcherTimer(); _timer.Interval = TimeSpan.FromMilliseconds(MainViewModel.CardLoadingDelay); //Just waiting to Sync any animation in the View _timer.Tick += new EventHandler(delegate(object s, EventArgs ev) { int index = indexCollection.Count - 1; if (index == -1) { _timer.Stop(); } else { CardPairs[indexCollection[index]].IsLoaded = true; indexCollection.RemoveAt(index); } }); _timer.Start(); }