I'm new to Unity and component-based programming and have a little problem. With so many card games, you'd think there would be some instruction on how to deal the cards, but there aren't...So, here I am.
I created a Card class, a card database, and a deck class. I created a GameObject in the Hierarchy that uses the deck class. Here's the deck class:
public class PlayerDeck : MonoBehaviour
{
public int d;
public List<Card> deck;
public List<Card> container;
public List<Card> distributed;
public List<Card> discarded;
public int decksize;
void Start()
{
LoadVariables();
LoadDeck();
ShuffleDeck()
}
public void LoadVariables()
{
d = 0;
decksize = 64;
}
public void LoadDeck()
{
for (int i = 0; i < 64; i++)
{
d = i;
deck[d] = CardDatabase.cardList[i];
}
}
public void ShuffleDeck()
{
for (int i=0; i<decksize; i++)
{
container[0] = deck[i];
int rnd = Random.Range(i, decksize);
deck[i] = deck[rnd];
deck[rnd] = container[0];
}
}
public void DealCards()
{
}
}
When I run this in debug, I can see the cards are shuffled. Now I need the deck to initially deal each player 7 cards like in UNO. This is where I don't understand component-based programming. If I have a GameObject called Deck, and 4 other GameObject for players, how can the 4 player gameobjects receive the cards the Deck deals them?
Any coding help would be appreciated.