/// <summary>
 /// Determines the winner if some user lefts the game.
 /// </summary>
 /// <param name="leftParticipantId"> The id of user who has left.
 /// If it is an empty string, consider that we have left. </param>
 private void ProcessPlayerLeft(string leftParticipantId)
 {
     if (myId == leftParticipantId || leftParticipantId == "")
     {
         //We have left, so we loose.
         currentUserResultType = UserResultType.LOSE;
     }
     else
     {
         //Another user left, so we win.
         currentUserResultType = UserResultType.WIN;
         multiplayerController.LeaveRoom();
     }
     CloseGame();
 }
        /// <inheritdoc />
        /// <summary>
        /// </summary>
        public override void InvokeState()
        {
            //Change the default input listener.
            inputListener = networkInputListener;
            //Perform common initialization.
            SetupGame();

            multiplayerController = MultiplayerController.GetInstance();
            multiplayerController.OnPlayerLeft += ProcessPlayerLeft;

            string hostId;

            //Maybe we do not need this try/catch anymore
            try
            {
                allPlayers = multiplayerController.GetAllPlayers();
                hostId     = ChooseHost();
                myId       = multiplayerController.GetMyParticipantId();
            }
            catch (Exception)
            {
                multiplayerController.LeaveRoom();
                stateManager.ChangeState(StateType.LOBBY_GAME_STATE);
                return;
            }

            isHost = false;

            //Let the host set up the round.
            if (hostId == myId)
            {
                isHost = true;
                SetupRoundHost();
                myTurnType = TurnType.FIRST;
                InitNewRound();
            }
            else
            {
                myTurnType = TurnType.SECOND;
                multiplayerController.OnMessageReceived += SetupRoundFromNetwork;
            }
        }
Ejemplo n.º 3
0
 private void DisplayAuthenticationError()
 {
     multiplayerController.LeaveRoom();
     stateManager.InfoGameState.SetInfoText("Authentication failed!\nPlease, try again.");
     stateManager.ChangeState(StateType.INFO_GAME_STATE);
 }
 private void DisplayOpponentDisconnected()
 {
     multiplayerController.LeaveRoom();
     stateManager.InfoGameState.SetInfoText(opponentDisconnectedString);
     stateManager.ChangeState(StateType.INFO_GAME_STATE);
 }