Exemplo n.º 1
0
 /// <summary>
 /// Must be called before usage.
 /// </summary>
 public void Initialize(ControllerManager controllerManager, int blockWidth, int blockHeight)
 {
     base.Initialize(controllerManager);
     this.blockWidth       = blockWidth;
     this.blockHeight      = blockHeight;
     multiplayerController = MultiplayerController.GetInstance();
     multiplayerController.OnMessageReceived += ProcessNetworkData;
 }
Exemplo n.º 2
0
 private void Awake()
 {
     multiplayerController = MultiplayerController.GetInstance();
     multiplayerController.OnRoomSetupCompleted   += OnOpponentFound;
     multiplayerController.OnRoomSetupError       += DisplayRoomSetupError;
     multiplayerController.OnOpponentDisconnected += DisplayOpponentDisconnected;
     multiplayerController.OnMessageReceived      += ProcessMessage;
     multiplayerController.OnAuthenticated        += DisplayAfterAuthenticatedMessage;
     multiplayerController.OnAuthenticationError  += DisplayAuthenticationError;
 }
        /// <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;
            }
        }
        /// <summary>
        /// Starts authentication and opponent searching process.
        /// </summary>
        public void InvokeState()
        {
            multiplayerController = MultiplayerController.GetInstance();
            lobbyText.text        = authenticationString;
            menuActivator.OpenMenu(lobbyMenu);
            SubscribeOnNetworkEvents();

            stateManager.NetworkPlayGameState.ConfigurationType = ConfigurationType;
            if (ConfigurationType == BoardType.SMALL)
            {
                multiplayerController.SignInAndStartMPGame(0);
            }
            else if (ConfigurationType == BoardType.LARGE)
            {
                multiplayerController.SignInAndStartMPGame(1);
            }

            exitListener.Enable();
            exitListener.OnExitClicked += OnExit;
        }
 public static MultiplayerController GetInstance()
 {
     return(instance ?? (instance = new MultiplayerController()));
 }