Exemple #1
0
 public static void GetGamesList()
 {
     if (cuenta != null)
     {
         EngineNetwork.Send(EngineNetwork.CreatePackage(new object[] {
             (byte)NetworkClientRequests.GetGames
         }));
         var gamesPackage = EngineNetwork.ReceiveMultipleData();
         if (gamesPackage.Count == 0)
         {
             return;
         }
         if (!gamesPackage[0].ContainsKey("code"))
         {
             return;
         }
         else if (byte.Parse(gamesPackage[0]["code"]) != (byte)NetworkServerResponses.GamesList)
         {
             return;
         }
         gamesPackage.RemoveAll(x => x.ContainsKey("code"));
         foreach (var gamePackage in gamesPackage)
         {
             System.Windows.Application.Current.Dispatcher.Invoke(delegate {
                 if (!GamesList.ToList().Exists(x => x.Id == int.Parse(gamePackage["idpartida"])))
                 {
                     var game = new Partida(
                         int.Parse(gamePackage["idpartida"]),
                         int.Parse(gamePackage["ronda"]),
                         Convert.ToDateTime(gamePackage["fecha"])
                         );
                     game.PropertyChanged += Game_PropertyChanged;
                     GamesList.Add(game);
                 }
                 else
                 {
                     GamesList.ToList().Find(x => x.Id == int.Parse(gamePackage["idpartida"])).LoadJugadores();
                 }
             });
         }
         List <Partida> gamesToRemove = new List <Partida>();
         foreach (var game in GamesList)
         {
             var checkGame = gamesPackage.ToList().Find(x => int.Parse(x["idpartida"]) == game.Id);
             if (checkGame == null)
             {
                 gamesToRemove.Add(game);
             }
         }
         System.Windows.Application.Current.Dispatcher.Invoke(delegate {
             gamesToRemove.ForEach(x => GamesList.Remove(x));
         });
     }
 }
 public void JoinGameIfNeeded()
 {
     Application.Current.Dispatcher.Invoke(delegate {
         if (!didCreateGame)
         {
             return;
         }
         Partida game = Session.GamesList.ToList().Find(
             x => x.Jugadores.Find(j => j.Cuenta.Id == Session.Cuenta.Id) != null
             );
         if (game == null)
         {
             return;
         }
         didCreateGame           = false;
         Session.GameLobbyWindow = new GameLobbyWindow(ref game);
         Session.GameLobbyWindow.Show();
         Hide();
     });
 }
Exemple #3
0
        public bool LeaveGame(Partida game)
        {
            EngineNetwork.Send(EngineNetwork.CreatePackage(new object[] {
                (byte)NetworkClientRequests.LeaveGame, id, game.Id
            }));
            var packageReceived = EngineNetwork.ReceiveMultipleData();

            if (packageReceived.Count == 0)
            {
                return(false);
            }
            else if (packageReceived.Count == 1)
            {
                if (byte.Parse(packageReceived[0]["code"]) != (byte)NetworkServerResponses.PlayerLeft)
                {
                    return(false);
                }
            }
            return(true);
        }
Exemple #4
0
        public bool JoinGame(Partida game)
        {
            var joinGameRequest = EngineNetwork.CreatePackage(new object[] {
                (byte)NetworkClientRequests.JoinGame, id, game.Id,
            });

            EngineNetwork.Send(joinGameRequest);
            List <string> packageReceived = EngineNetwork.Receive();

            if (packageReceived.Count == 0)
            {
                return(false);
            }
            else if (packageReceived.Count == 1)
            {
                if (byte.Parse(packageReceived[0]) != (byte)NetworkServerResponses.PlayerJoined)
                {
                    return(false);
                }
            }
            return(true);
        }