Example #1
0
    public void AddMoreCards()
    {
        List <int> newCards = new List <int>();

        // 3 cards in a set.
        List <GameObject> cardsToDelete = new List <GameObject>();

        for (int i = 0; i < propPlacement.cards.Length; i++)
        {
            if (!propPlacement.cards[i].activeSelf)
            {
                cardsToDelete.Add(propPlacement.cards[i]);
                webSocketManager.SendLog("marking card " + CardProperties.Stringify(propPlacement.cards[i]) + " to delete");

                // If not in a reset state, generate a card to put in this spot instead.
                if (!reset)
                {
                    propPlacement.cards[i] = cardGenerator.GenCard();
                    newCards.Add(i);
                }
                else
                {
                    propPlacement.cards[i] = null;
                }
            }
        }

        if (!reset)
        {
            while (!SetsExist(propPlacement.cards))
            {
                foreach (int i in newCards)
                {
                    Destroy(propPlacement.cards[i]);
                    propPlacement.cards[i] = cardGenerator.GenCard();
                }
            }
            foreach (int i in newCards)
            {
                var rndGoodCell = hexgrid.GetRandomGrassOrPathCell();
                while (propPlacement.propLocs.Contains(rndGoodCell))
                {
                    rndGoodCell = hexgrid.GetRandomGrassOrPathCell();
                }

                propPlacement.cards[i].transform.position = rndGoodCell.transform.position;
                propPlacement.propLocs.Add(rndGoodCell);
                propPlacement.walkableLocs.Add(rndGoodCell);
            }
        }

        // Then you delete the cards.
        foreach (var card in cardsToDelete)
        {
            if (card != null)
            {
                webSocketManager.SendLog("about to destroy card " + CardProperties.Stringify(card));
                Destroy(card);
            }
        }

        cardsToDelete.Clear();
        webSocketManager.SendLog("successfully destroyed all previous cards");

        Debug.Log("Reset: " + reset);
        Debug.Log("Cards:");
        for (int i = 0; i < propPlacement.cards.Length; i++)
        {
            Debug.Log(propPlacement.cards[i]);
        }
    }