Beispiel #1
0
        public List <TTCardData> GetRandomCardData(int count)
        {
            if (count > _cardData.Length)
            {
                Debug.LogError($"Card data is less than request count {count}");
                return(null);
            }

            List <TTCardData> randomCards = new List <TTCardData>();

            int[] candidatesOfIndex = Enumerable.Range(0, _cardData.Length).ToArray();
            int   candidateRange    = candidatesOfIndex.Length;

            for (int i = 0; i < count; i++)
            {
                int randomCandidateIndex = Random.Range(0, candidateRange);
                int newCardIndex         = candidatesOfIndex[randomCandidateIndex];
                Swap(ref candidatesOfIndex[randomCandidateIndex], ref candidatesOfIndex[candidateRange - 1]);
                candidateRange -= 1;

                TTCardData newCard = _cardData[newCardIndex];
                randomCards.Add(newCard);
            }

            return(randomCards);
        }
Beispiel #2
0
 public TTCard(TTCardData data, int playerId)
 {
     cardData       = data;
     rankDifference = 0;
     belongPlayerId = playerId;
 }