/// <summary> /// Builds the deck. /// </summary> /// <returns>The deck.</returns> void BuildDeck() { CA card = null; int id = 0; for (int i = 0; i < totalSets; i++) { List<string> pictureParts = new List<string>(); for (int j = 0; j < matchesPerCard; j++) { string partName = string.Format("_{0}", j + 1); pictureParts.Add(partName); } for (int j = 0; j < matchesPerCard; j++) { int someNumber = Random.Range(0, pictureParts.Count); string missingPart = pictureParts [someNumber]; pictureParts.RemoveAt(someNumber); string imageName = string.Format("picture-{0}{1}", (i + 1), missingPart); string imageId = string.Format("{0}{1}", i, missingPart); card = new CA(imageName, imageId); _aCards.Add(card); card = new CA(imageName, imageId); _aCards.Add(card); id++; } } }
IEnumerator FlipCardFaceUp(CA card) { card.isFaceUp = true; if (_cardsFlipped.IndexOf(card) < 0) { _cardsFlipped.Add(card); if (_cardsFlipped.Count == 2) { playerCanClick = false; yield return new WaitForSeconds(1.5f); if (MatchingCards(_cardsFlipped [1].id, _cardsFlipped [0].id)) { _cardsFlipped [0].isMatched = true; _cardsFlipped [1].isMatched = true; _matchesMade++; if (_matchesMade >= matchesNeedToWin) { playerHasWon = true; } } else { _cardsFlipped [0].isFaceUp = false; _cardsFlipped [1].isFaceUp = false; } _cardsFlipped = new List<CA>(); playerCanClick = true; } } }