private void btnFlip_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem toolStripMenuItem = sender as ToolStripMenuItem;

            FlipType = toolStripMenuItem?.Name;
            FlipAction?.Invoke();
        }
Beispiel #2
0
 void Start()
 {
     card1 = null;
     card2 = null;
     //flipBackCards = new ArrayList();
     //flipBackTimer = new ArrayList();
     Score           = 0;
     cardPicker      = gameObject.GetComponent("CardPicker") as CardPicker;
     flipToATimer    = 0;
     cardsDoNotMatch = false;
 }
Beispiel #3
0
 private void AddCard(FlipAction card)
 {
     if (card != null && card.tag == "card")
     {
         card.FlipToB();
         if (card1 == null)
         {
             card1 = card;
             card1.Clicks++;
         }
         else if (card1 != card && card2 == null)
         {
             card2 = card;
             card2.Clicks++;
         }
     }
     //print(card1);
     //print(card2);
 }
Beispiel #4
0
 private void FillGrid(int pairOfCards)
 {
     for (int i = 0; i < pairOfCards; i++)
     {
         if (transform.childCount / 2 > cardFaces.Length)
         {
             break;
         }
         for (int c = 0; c < 2; c++)
         {
             FlipAction card = Instantiate(cardSample) as FlipAction;
             //print(card);
             card.transform.parent        = transform;
             card.transform.localPosition = GetFreeCell();
             card.sideBSprite             = cardFaces[i];
             TotalCardCount++;
         }
     }
 }
Beispiel #5
0
    /// <summary>
    /// Compare the cards in card1 and card2.
    /// Add score if equal and add moves based on total clicks in the cards.
    /// Prepare variables, card1 and card2, for the new cards clicked.
    /// If not equal, flip back to sideA.
    /// </summary>
    private void CompareCards()
    {
        if (card1 != null && card2 != null && !cardsDoNotMatch)
        {
            // Wait until the cards are flipped to sideB
            // If we don't, the moment you click the second card, both will be compared
            // and we might not get a chance to see what's behind the second card
            if (card1.IsOnSideB && card2.IsOnSideB)
            {
                if (card1.sideBSprite == card2.sideBSprite)
                {
                    Score++;
                    Moves += GetReward(card1.Clicks, card2.Clicks);
                    //print("Score: " + Score);
                    cardPicker.Clear();
                    card1           = null;
                    card2           = null;
                    flipToATimer    = 0;
                    cardsDoNotMatch = false;
                }
                else
                {
                    Moves--;
                    //flipBackCards.Add(card1);
                    //flipBackTimer.Add(0f);
                    //flipBackCards.Add(card2);
                    //flipBackTimer.Add(0f);
                    cardsDoNotMatch = true;
                }

                //cardPicker.Clear();
                //card1 = null;
                //card2 = null;
                //card1Clicks = null;
                //card2Clicks = null;
            }
        }
    }
Beispiel #6
0
    // Update is called once per frame
    void Update()
    {
        if (card1 != null && card2 != null)
        {
            return;
        }

        #region Detect mouse/touch events
        if (useTouch)
        {
            if (Input.touchCount == 1 && Input.GetTouch(0).phase == TouchPhase.Began)
            {
                tempCard = GetCard();
                if (tempCard != null)
                {
                    tempCard.sideASprite = spritePressed;
                }
            }
            else if (Input.touchCount == 1 && Input.GetTouch(0).phase == TouchPhase.Ended)
            {
                FlipAction card = GetCard();
                if (card != null)
                {
                    if (tempCard == card)
                    {
                        AddCard(card);
                    }
                }

                if (tempCard != null)
                {
                    tempCard.sideASprite = spriteIdle;
                }
            }
        }
        else
        {
            if (Input.GetMouseButtonDown(0))
            {
                tempCard = GetCard();
                if (tempCard != null)
                {
                    tempCard.sideASprite = spritePressed;
                }
            }
            else if (Input.GetMouseButtonUp(0))
            {
                FlipAction card = GetCard();
                if (card != null)
                {
                    if (tempCard == card)
                    {
                        AddCard(card);
                    }
                }

                if (tempCard != null)
                {
                    tempCard.sideASprite = spriteIdle;
                }
            }
        }
        #endregion
    }
Beispiel #7
0
 public void Clear()
 {
     card1 = null;
     card2 = null;
 }
Beispiel #8
0
 void Start()
 {
     objFlipAction  = otherObject.GetComponent("FlipAction") as FlipAction;
     objScaleAction = otherObject.GetComponent("ScaleAction") as ScaleAction;
 }
Beispiel #9
0
    void Update()
    {
        card1 = cardPicker.Card1;
        card2 = cardPicker.Card2;
        CompareCards();

        if (cardsDoNotMatch)
        {
            flipToATimer += Time.deltaTime;
            if (flipToATimer >= flipToADelay)
            {
                card1.FlipToA();
                card2.FlipToA();
            }
            if (card1.IsOnSideA && card2.IsOnSideA)
            {
                cardPicker.Clear();
                card1           = null;
                card2           = null;
                flipToATimer    = 0;
                cardsDoNotMatch = false;
            }
        }

        // Delay cards' flip action
        //for(int i = 0; i < flipBackTimer.Count; i++) {
        //    float timer = (float)flipBackTimer[i];
        //    timer += Time.deltaTime;

        //    if(timer >= flipBackDelay) {
        //        FlipAction card = flipBackCards[i] as FlipAction;
        //        card.FlipToA();
        //        //(card.gameObject.GetComponent("Collider2D") as Collider2D).enabled = true;

        //        flipBackCards.RemoveAt(i);
        //        flipBackTimer.RemoveAt(i);
        //        //continue;
        //    }
        //    else
        //        flipBackTimer[i] = timer;
        //}

        //#region Flip to A delay timer
        //ArrayList forRemoval = new ArrayList();     // Cards to be removed in flipBackCards
        //foreach(FlipAction card in flipBackCards) {
        //    int index = flipBackCards.IndexOf(card);
        //    float timer = (float)flipBackTimer[index];
        //    timer += Time.deltaTime;
        //    flipBackTimer[index] = timer;

        //    if(timer >= flipBackDelay) {
        //        card.FlipToA();
        //        forRemoval.Add(index);
        //    }
        //}
        //// Remove
        //for(int i = forRemoval.Count - 1; i >= 0; i--) {
        //    flipBackCards.RemoveAt(i);
        //    flipBackTimer.RemoveAt(i);
        //}
        //#endregion
    }