예제 #1
0
        void CarregaMapa()
        {
            foreach (var gamer in rede.LocalGamers) {
                if (gamer.IsHost && null == mapa) {
                    mapa = new Mapa (new Vector2 (0f, 0f));
                    mapa.Initialize ();
                }
                if (null != mapa) {
                    caixaSaida.Write (mapa.Descricao);
                    Console.WriteLine ("Enviei mapa");
                } else
                    caixaSaida.Write ("");
                gamer.SendData (caixaSaida, SendDataOptions.Reliable);
            }

            rede.Update ();
            if (null == rede)
                return;

            String descricaoRemota = "";
            bool ok = true;

            foreach (LocalNetworkGamer gamer in rede.LocalGamers)
                while (gamer.IsDataAvailable) {
                    NetworkGamer remetente;
                    gamer.ReceiveData (caixaEntrada, out remetente);
                    if (remetente.IsLocal)
                        continue;
                    string descricaoAux = caixaEntrada.ReadString ();
                    if (!String.IsNullOrEmpty (descricaoAux))
                        descricaoRemota = descricaoAux;
                    ok = ok && !String.IsNullOrEmpty (descricaoAux);
                }

            if (!String.IsNullOrEmpty (descricaoRemota) && null == mapa) {
                mapa = new Mapa (new Vector2 (0.0f, 0.0f));
                mapa.Initialize (descricaoRemota);
                mapa.LoadContent (Content);
            }

            if (ok && rede.RemoteGamers.Count > 0 && null != mapa)
                estado_atual = EstadoDeJogo.Loading;
        }
예제 #2
0
 protected void JoinSessao()
 {
     estado_atual = EstadoDeJogo.Loading;
     try {
         using (AvailableNetworkSessionCollection disponiveis = NetworkSession.Find(NetworkSessionType.SystemLink, 2,null)) {
             if (disponiveis.Count != 0) {
                 rede = NetworkSession.Join (disponiveis [0]);
                 mapa = new Mapa(new Vector2(0f,0f));
                 mapa.Initialize();
                 mapa.LoadContent(Content);
                 estado_atual = EstadoDeJogo.Mapa;
                 ManipulaEventos ();
             } else {
                 return;
             }
         }
     } catch (Exception ex) {
         // Faca nada
     }
 }