Esempio n. 1
0
    public void SetupLevel(bool restart = false)
    {
        if (restart == true)
        {
            levelNo--;
        }

        // Destroy old cards
        foreach (GameObject go in cardGoList)
        {
            Destroy(go);
        }

        cardGoList.Clear();

        // Set up variables
        timePassed            = 0;
        wrongTries            = 0;
        nextNumber            = 1;
        timeFlowFactor        = 1f;
        levelStarted          = false;
        levelFinished         = false;
        levelCompleted        = false;
        UICont.lastOpenedCard = null;
        levelNo++;

        currLevel = levels[levelNo - 1];

        UICont.SetLevelText(levelNo);
        UICont.SetupUI();

        List <int> numbers = setNumbersList();

        for (int cardNo = 1; cardNo <= tableSize; cardNo++)
        {
            Transform card = Instantiate(cardPrefab, tableTransform).transform;
            cardGoList.Add(card.gameObject);

            if (currLevel.design.Contains(cardNo) == false)
            {
                Card cardComponenet = card.GetComponent <Card>();
                cardComponenet.active = false;
            }
            else
            {
                int  index          = Random.Range(0, numbers.Count);
                Card cardComponenet = card.GetComponent <Card>();

                cardComponenet.active     = true;
                cardComponenet.cardNumber = numbers[index];

                numbers.RemoveAt(index);
            }
        }
    }