Exemplo n.º 1
0
    IEnumerator FlipBackCards(LargeCard a, LargeCard b)
    {
        yield return(new WaitForSeconds(FlipBackDelay + a.SpinDuration));

        SetFlippingChildren(true);
        ignoreSet.Remove(a.transform);
        ignoreSet.Remove(b.transform);
        a.SpinCard();
        b.SpinCard();
        ForceCardsOver();
    }
Exemplo n.º 2
0
    void TappedCard(PointerEventData data)
    {
        //Ignore these flip events
        if (lockedSpin)
        {
            return;
        }
        GameObject go    = data.pointerCurrentRaycast.gameObject;
        LargeCard  lCard = go.GetComponentInParent <LargeCard>();

        if (!lCard.CanSpin || (selectedCard != null && !selectedCard.CanSpin) || ignoreSet.Contains(lCard.transform))
        {
            return;
        }
        if (selectedCard == null)
        {
            selectedCard = lCard;
        }
        else if (selectedCard == lCard)
        {
            selectedCard = null;
        }
        else
        {
            //Selected the correct second card (has to be facing the other way)
            if (lCard.GetCardData() == selectedCard.GetCardData() && (lCard.hideType != selectedCard.hideType))
            {
                //Disable interactivity
                //Can't just set canspin because canspin is constantly reset (can make it only reset cards that aren't in solved hashset if necessary)
                CanvasGroup lCardGroup    = lCard.GetComponent <CanvasGroup>();
                CanvasGroup selectedGroup = selectedCard.GetComponent <CanvasGroup>();
                lCardGroup.interactable      = false;
                selectedGroup.interactable   = false;
                lCardGroup.blocksRaycasts    = false;
                selectedGroup.blocksRaycasts = false;

                //Ignore these cards when forcing all cards to flip over
                ignoreSet.Add(lCard.transform);
                ignoreSet.Add(selectedCard.transform);

                //Show some other way that it was correct
                lCard.GetComponent <Image>().color        = Color.cyan;
                selectedCard.GetComponent <Image>().color = Color.cyan;
                ForceCardsOver();
                selectedCard = null;

                cardsCompleted += 2;
                CheckGameCompleted();
            }
            else
            {
                //Make sure second card is still flipped due to how events are passed
                lCard.SpinCard();
                //Force all other children cards over if they aren't in hashSet of solved cards or selected cards
                ignoreSet.Add(lCard.transform);
                ignoreSet.Add(selectedCard.transform);
                ForceCardsOver();
                //Enforce a delay to see that you made a mistake
                SetFlippingChildren(false);
                StartCoroutine(FlipBackCards(lCard, selectedCard));
                //Wrong second card, lock out spinning of all the cards in order to show mistake
                selectedCard = null;
            }
        }
    }