#Card game player deck

1 messages · Page 1 of 1 (latest)

prime plaza
#

So I'm making a card game and I have a card database with 42 unique cards and when I play I made it so that it creates a random deck using those cards, but how could I make it so that there is not two of the same card?

Here is the code I used to far to generate the player deck:

using System.Collections.Generic;
using UnityEngine;

public class PlayerDeck : MonoBehaviour
{
    public List<Card> deck = new List<Card>();
    public int x;
    // Start is called before the first frame update
    void Start()
    {
        
        x = 0;

        for(int i = 0; i < 42; i++)
        {
            x = Random.Range(1, CardDatabase.cardList.Count);
            deck[i] = CardDatabase.cardList[x];
        }

    }

    // Update is called once per frame
    void Update()
    {
        
    }
}```
tacit tulip
#

Duplicate your list of cards, use the duplicate as a base to get random cards from, and every time you add a card to your deck, remove it from that list.

prime plaza
#

How could I remove it from the list?

tacit tulip
#

that's something you can google.

prime plaza
#

Alright, will do so, what is the reason behind making a duplicate of the list though? Wouldn't it be possible to use the original list?

civic minnow
#

You should google for a card shuffling algorithm

#

The shuffle you have there doesn't really work.

prime plaza