Esempio n. 1
0
        public MainPageVM()
        {
            conn  = new HubConnection("http://localhost:54209/");
            proxy = conn.CreateHubProxy("PongHub");
            conn.Start();
            dispatcherTimer          = new DispatcherTimer();
            dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 1);
            dispatcherTimer.Tick    += timerTick;

            _dispatcher = Window.Current.Dispatcher;

            _objetosJuego = new List <objetoJuego>();
            objetoJuego _jugador1 = new objetoJuego(0.0, "jugador1", "jugador1", false, 50, 300, new Uri("ms-appx:///Assets/barra.png"));
            objetoJuego _jugador2 = new objetoJuego(880, "jugador2", "jugador2", false, 50, 300, new Uri("ms-appx:///Assets/barra.png"));
            objetoJuego _pelota   = new objetoJuego(250, "pelota", "pelota", false, 100, 500, null);

            _objetosJuego.Add(_jugador1);
            _objetosJuego.Add(_jugador2);
            _objetosJuego.Add(_pelota);

            do
            {
                if (conn.State == ConnectionState.Connected)
                {
                    getCliente();
                    proxy.Invoke("añadirObjetoJuego", _objetosJuego[0].id);
                    proxy.Invoke("añadirObjetoJuego", _objetosJuego[1].id);
                    proxy.Invoke("añadirObjetoJuego", _objetosJuego[2].id);
                    proxy.On <objetoJuego>("actualizarPosicionObjeto", actualizarPosicionObjeto);
                }
            } while (conn.State != ConnectionState.Connected);
        }
Esempio n. 2
0
 public async void actualizarPosicionObjeto(objetoJuego objetoJuego)
 {
     await _dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() => {
         foreach (var index in _objetosJuego)
         {
             if (index.id == objetoJuego.id)
             {
                 index.izquierda = objetoJuego.izquierda;
                 index.posicionY = objetoJuego.posicionY;
             }
         }
         NotifyPropertyChanged("objetosJuegos");
     });
 }