Example #1
0
        void OnGameStarted()
        {
            if (PhotonNetwork.IsMasterClient)
            {
                leastCountManager.Shuffle();
                List <byte> player1Values    = leastCountManager.DealCardValuesToPlayer(localPlayer, Constants.PLAYER_INITIAL_CARDS);
                List <byte> player2Values    = leastCountManager.DealCardValuesToPlayer(remotePlayer, Constants.PLAYER_INITIAL_CARDS);
                List <byte> poolOfCards      = leastCountManager.GetPoolOfCards();
                byte        droppedCardValue = leastCountManager.FirstDroppedCard();
                List <byte> droppedListValue = new List <byte>();
                droppedListValue.Add(droppedCardValue);

                Dictionary <string, byte[]> dict = new Dictionary <string, byte[]>();
                dict.Add(localPlayer.PlayerId, player1Values.ToArray());
                dict.Add(remotePlayer.PlayerId, player2Values.ToArray());
                dict.Add("poolOfCards", poolOfCards.ToArray());
                dict.Add(Constants.INITIALIZING_DROPPEDCARD, droppedListValue.ToArray());

                currentTurnPlayer = localPlayer;

                //Hashtable props = new Hashtable
                //{
                //{Constants.INITIALIZING_CARDS, dict}
                //};
                //PhotonNetwork.CurrentRoom.SetCustomProperties(props);

                byte evCode = 1; // Custom Event 1: Used as "MoveUnitsToTargetPosition" event
                //object[] content = new object[] { dict }; // Array contains the target position and the IDs of the selected units
                RaiseEventOptions raiseEventOptions = new RaiseEventOptions {
                    Receivers = ReceiverGroup.All
                };                                                                                             // You would have to set the Receivers to All in order to receive this event on the local client as well
                PhotonNetwork.RaiseEvent(evCode, dict, raiseEventOptions, SendOptions.SendReliable);
                Debug.Log("master onstarted");
                cardAnimator.DealDisplayingCards(localPlayer, Constants.PLAYER_INITIAL_CARDS);
                cardAnimator.DealDisplayingCards(remotePlayer, Constants.PLAYER_INITIAL_CARDS);
                Card firstDroppedCard = cardAnimator.DropFirstCard(droppedCardValue);
                leastCountManager.AddToDropCardsReference(firstDroppedCard);
            }
            else
            {
                if (intializing && !PhotonNetwork.IsMasterClient)
                {
                    cardAnimator.DealDisplayingCards(localPlayer, Constants.PLAYER_INITIAL_CARDS);
                    cardAnimator.DealDisplayingCards(remotePlayer, Constants.PLAYER_INITIAL_CARDS);
                    Card firstDroppedCard = cardAnimator.DropFirstCard(leastCountManager.GetDroppedCardValues()[0]);
                    leastCountManager.AddToDropCardsReference(firstDroppedCard);
                    intializing = false;
                }
            }
        }