PUN Shuffling Cards

Options
Hello !

i'm developing a multiplayer card game. I understand that for shuffling the cards it should be done by the master client but i have problem that the card with the same suit and value can be more than one in the cards list.
Hope someone can help. Below is the code :


public void StartGame()
{

if(PhotonNetwork.isMasterClient)
{

for(int i= 0; i<listcards.Count; i++)
{

int rnd = Random.Range(0, listcards.Count);
photonView.RPC("ShuffleCards", PhotonTargets.All, i, rnd);

}



public void ShuffleCards(int i, int rnd)
{

Card temp = new Card();

temp = listcards[i];
listcards[i] = listcards[rnd]
listcards[rnd] = temp;

}

Comments

  • Hi @liorium,

    do other players need to shuffle the cards, too? Do they need to have an up to date list? If not maybe it is easier to just shuffle the cards on the MasterClients and let him deal the cards to other players. If they need the shuffled card list, too, maybe it is enough to just send one RPC or raise a single event after the cards have been shuffled by the MasterClient.

    For the shuffling itself you might want to search for how to shuffle or randomize a list.
  • liorium
    Options
    Thanks ! @Christian_Simon