Exemple #1
0
    public void OnPlayerFinished(Player player, int turn, object move)
    {
        bool finishedByLocal  = turnManager.GetPlayerFinishedTurn(PhotonNetwork.LocalPlayer);
        bool finishedByRemote = turnManager.GetPlayerFinishedTurn(PhotonNetwork.PlayerListOthers[0]);



        Debug.Log(">>>>>>> local:" + finishedByLocal + " VS remote: " + finishedByRemote + " <<<<<");
        if (player == PhotonNetwork.LocalPlayer) //Local is the one who finished
        {
            isMyTurn = false;
            gameManager.EndTurn();
            Debug.Log("I just finished! -------");
            Debug.Log("  -Local Player property 'turn' set to false and remote to true!");
        }
        else
        {
            Debug.Log("The other player just finished! -------");
            isMyTurn = true;
            gameManager.DecodeMove(move);
        }


        Debug.Log("Pieces: local: " + gameManager.controller.localPlayerInfo.listOfPlayedPositions.Count + " VS " + gameManager.controller.remotePlayerInfo.listOfPlayedPositions.Count);
        if (gameManager.CheckIfAnyWinner())
        {
            Debug.Log("Someone won or there is a tie");
            gameManager.EndOfROund();
            Debug.Log("**********END ROUND********");
        }
        else if (isMyTurn)
        {
            turnManager.BeginTurn();
            Debug.Log("The round has ended. Because: " + gameManager.messageLog);

            //gameManager.SomethingHappened(msg);
        }
        Debug.Log("############TURN END############");
    }
Exemple #2
0
    public void Update()
    {
        // Check if we are out of context, which means we likely got back to the demo hub.
        if (!DisconnectedPanel)
        {
            Destroy(gameObject);
        }

        if (!PhotonNetwork.inRoom)
        {
            return;
        }

        // disable the "reconnect panel" if PUN is connected or connecting
        if (PhotonNetwork.connected && DisconnectedPanel.gameObject.GetActive())
        {
            DisconnectedPanel.gameObject.SetActive(false);
        }
        if (!PhotonNetwork.connected && !PhotonNetwork.connecting && !DisconnectedPanel.gameObject.GetActive())
        {
            DisconnectedPanel.gameObject.SetActive(true);
        }


        if (PhotonNetwork.room.PlayerCount > 1)
        {
            if (turnManager.IsOver)
            {
                return;
            }

            /*
             * // check if we ran out of time, in which case we loose
             * if (turnEnd<0f && !IsShowingResults)
             * {
             *              Debug.Log("Calling OnTurnCompleted with turnEnd ="+turnEnd);
             *              OnTurnCompleted(-1);
             *              return;
             * }
             */

            if (TurnText)
            {
                TurnText.text = turnManager.Turn.ToString();
            }

            if (turnManager.Turn > 0 && TimeText && !IsShowingResults)
            {
                TimeText.text            = turnManager.RemainingSecondsInTurn.ToString("F1") + " SECONDS";
                TimerFillImage.anchorMax = new Vector2(1f - turnManager.RemainingSecondsInTurn / turnManager.TurnDuration, 1f);
            }
        }

        UpdatePlayerTexts();

        // show local player's selected hand
        Sprite selected = SelectionToSprite(localSelection);

        if (selected)
        {
            localSelectionImage.gameObject.SetActive(true);
            localSelectionImage.sprite = selected;
        }

        // remote player's selection is only shown, when the turn is complete (finished by both)
        if (turnManager.IsCompletedByAll)
        {
            selected = SelectionToSprite(remoteSelection);
            if (selected)
            {
                remoteSelectionImage.color  = new Color(1, 1, 1, 1);
                remoteSelectionImage.sprite = selected;
            }
        }
        else
        {
            ButtonCanvasGroup.interactable = PhotonNetwork.room.PlayerCount > 1;

            if (PhotonNetwork.room.PlayerCount < 2)
            {
                remoteSelectionImage.color = new Color(1, 1, 1, 0);
            }

            // if the turn is not completed by all, we use a random image for the remote hand
            else if (turnManager.Turn > 0 && !turnManager.IsCompletedByAll)
            {
                // alpha of the remote hand is used as indicator if the remote player "is active" and "made a turn"
                PhotonPlayer remote = PhotonNetwork.player.GetNext();
                float        alpha  = 0.5f;
                if (turnManager.GetPlayerFinishedTurn(remote))
                {
                    alpha = 1;
                }
                if (remote != null && remote.IsInactive)
                {
                    alpha = 0.1f;
                }

                remoteSelectionImage.color  = new Color(1, 1, 1, alpha);
                remoteSelectionImage.sprite = SelectionToSprite(randomHand);
            }
        }
    }