Exemplo n.º 1
0
 /// <summary>
 /// Establishes a connection with game service to get all the games in course and waiting for players to be joined.
 /// </summary>
 public static void GetGamesList()
 {
     while (true)
     {
         bool valueReturned = EngineNetwork.EstablishChannel <IGameService>((service) => {
             while (mainMenuWindow != null)
             {
                 if (IsPlayerInGame)
                 {
                     GetGameBeingPlayedData(service);
                     continue;
                 }
                 List <Services.Game> serviceGamesList = service.GetGamesList();
                 foreach (Services.Game serviceGame in serviceGamesList)
                 {
                     SetServiceGame(serviceGame);
                 }
                 RemoveUnnecesaryGames(serviceGamesList);
             }
             return(true);
         });
         if (valueReturned)
         {
             break;
         }
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Establishes a connection with account service to try to register an account
 /// with the data stored in this account instance.
 /// </summary>
 /// <returns>True if account was registered successfully; False if not</returns>
 public bool Register()
 {
     return(EngineNetwork.EstablishChannel <IAccountService>((registerService) => {
         Services.Account account = new Services.Account(
             0, username, password, email, 0, DateTime.Now, false, null
             );
         return registerService.SignUp(account);
     }));
 }
Exemplo n.º 3
0
        /// <summary>
        /// Establishes a connnection with game service to try to create a new game.
        /// </summary>
        /// <param name="guidGame">
        /// Stores a global unique identifier that identifies the new game created.
        /// If game couldn't be created, this value will be empty.
        /// </param>
        /// <returns>True if creation request was successful; False if not</returns>
        public bool CreateGame(out string guidGame)
        {
            string guidNewGame   = "";
            bool   returnedValue = EngineNetwork.EstablishChannel <IGameService>((service) => {
                return(service.CreateGame(out guidNewGame, App.Language));
            });

            guidGame = guidNewGame;
            return(returnedValue);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Establishes a connnection with game service to try to join to a game.
        /// </summary>
        /// <param name="game">Game to join in</param>
        /// <param name="asAnfitrion">True to join as host; False to join as guest</param>
        /// <param name="guidPlayer">Player global unique identifier generated</param>
        /// <returns>True if join request was successful; False if not</returns>
        public bool JoinGame(Game game, bool asAnfitrion, out string guidPlayer)
        {
            string guidNewPlayer = "";
            bool   returnedValue = EngineNetwork.EstablishChannel <IGameService>((service) => {
                return(service.AddPlayer(id, game.ActiveGuidGame, asAnfitrion, out guidNewPlayer));
            });

            guidPlayer = guidNewPlayer;
            return(returnedValue);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Establishes a connection with game service to get a game category word.
        /// </summary>
        /// <param name="category">GameCategory that needs the word</param>
        /// <returns>
        ///     Empty string if word couldn't be found; otherwise, a random word whose
        ///     first letter is accord to the selected for the actual round.
        /// </returns>
        public string GetCategoryWord(GameCategory category)
        {
            var word = string.Empty;

            EngineNetwork.EstablishChannel <IGameService>((service) => {
                word = service.GetCategoryWord(game.ActiveGuidGame, activePlayerGuid, category.Name);
                return(true);
            });
            return(word);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Establishes a connnection with account service to get the account rank.
        /// </summary>
        /// <returns>
        /// If this account has games played, will return rank as #N, where N is the place.
        /// If it has no games played, will return a "Not ranked" string.
        /// </returns>
        public string GetRank()
        {
            var rank = Properties.Resources.NotRankedText;

            EngineNetwork.EstablishChannel <IAccountService>((service) => {
                var accountRank = service.GetRank(id);
                rank            = string.IsNullOrEmpty(accountRank) ? rank : accountRank;
                return(true);
            });
            return(rank);
        }
Exemplo n.º 7
0
 /// <summary>
 /// Establishes a connection with game service to start the game, increasing round value in 1.
 /// </summary>
 /// <returns>True if game was started successfully; False if not, or if round value was higher or equal to max rounds per game value</returns>
 public bool Start()
 {
     if (round >= Session.MAX_ROUNDS_PER_GAME)
     {
         return(false);
     }
     round += 1;
     return(EngineNetwork.EstablishChannel <IGameService>((service) => {
         return service.StartGame(ActiveGuidGame);
     }));
 }
Exemplo n.º 8
0
        /// <summary>
        /// Establishes a connection with game service to try to send the player answers from each game category.
        /// </summary>
        /// <param name="categoryPlayerAnswers">Category answers</param>
        /// <returns>True if operation was successful; False if not</returns>
        public bool SendCategoryAnswers(List <CategoryPlayerAnswer> categoryPlayerAnswers)
        {
            List <Services.CategoryPlayerAnswer> categoryPlayerAnswersService = new List <Services.CategoryPlayerAnswer>();

            foreach (var categoryPlayerAnswer in categoryPlayerAnswers)
            {
                categoryPlayerAnswersService.Add(new Services.CategoryPlayerAnswer {
                    Answer       = categoryPlayerAnswer.Answer,
                    Round        = categoryPlayerAnswer.Round,
                    GameCategory = new Services.GameCategory(0, null, categoryPlayerAnswer.GameCategory.Name)
                });
            }
            return(EngineNetwork.EstablishChannel <IGameService>((service) => {
                return service.SendCategoryAnswers(game.ActiveGuidGame, activePlayerGuid, categoryPlayerAnswersService);
            }));
        }
Exemplo n.º 9
0
 /// <summary>
 /// Establishes a connection with account service to try to reload account data.
 /// </summary>
 /// <returns>True if account data was reloaded successfully; False if not</returns>
 public bool Reload()
 {
     return(EngineNetwork.EstablishChannel <IAccountService>((loginService) => {
         var account = loginService.GetAccount(id);
         if (account.Id == 0)
         {
             return false;
         }
         username = account.Username;
         password = account.Password;
         email = account.Email;
         coins = account.Coins;
         creationDate = account.CreationDate;
         isVerified = account.IsVerified;
         validationCode = account.ValidationCode;
         return true;
     }));
 }
Exemplo n.º 10
0
 /// <summary>
 /// Establishes a connection with account service to load the scores list.
 /// </summary>
 private void LoadScoresList()
 {
     if (!EngineNetwork.EstablishChannel <IAccountService>((service) => {
         var scoresList = service.GetBestScores();
         scoresList.ForEach((userScore) => {
             bestScoresList.Add(new UserScore {
                 Ranking = userScore.Ranking,
                 Username = userScore.Username,
                 Score = userScore.Score
             });
         });
         return(true);
     }))
     {
         MessageBox.Show(Properties.Resources.AnErrorHasOcurredErrorText);
         Close();
     }
 }
Exemplo n.º 11
0
 /// <summary>
 /// Establishes a connection with game service to try to set a new ready status.
 /// </summary>
 /// <param name="isReady">True if player is ready; False if not</param>
 /// <returns>True if operation was successful; False if not</returns>
 public bool SetPlayerReady(bool isReady)
 {
     return(EngineNetwork.EstablishChannel <IGameService>((service) => {
         return service.SetPlayerReady(game.ActiveGuidGame, activePlayerGuid, isReady);
     }));
 }
Exemplo n.º 12
0
 /// <summary>
 /// Establishes a connection with game service to try to leave from the actual game.
 /// </summary>
 /// <param name="game">Game to leave</param>
 /// <returns>True if operation was successful; False if not</returns>
 public bool LeaveGame(Game game)
 {
     return(EngineNetwork.EstablishChannel <IGameService>((service) => {
         return service.RemovePlayer(activePlayerGuid, game.ActiveGuidGame);
     }));
 }
Exemplo n.º 13
0
 /// <summary>
 /// Establishes a connection with game service to set the letter to be played.
 /// </summary>
 /// <param name="selectRandomLetter">True if letter should be selected randomly</param>
 /// <param name="idaccount">Account identifier who made the choice</param>
 /// <param name="letter">Letter to be selected if random option was not selected</param>
 /// <returns>True if letter was set successfully; False if not</returns>
 public bool SetLetter(bool selectRandomLetter, int idaccount, string letter = null)
 {
     return(EngineNetwork.EstablishChannel <IGameService>((service) => {
         return service.SetGameLetter(ActiveGuidGame, idaccount, selectRandomLetter, letter);
     }));
 }
Exemplo n.º 14
0
 /// <summary>
 /// Establishes a connection with game service to remove a GameCategory from the game.
 /// </summary>
 /// <param name="category">GameCategory to be removed</param>
 /// <returns>True if category was removed successfully; False if not</returns>
 public bool RemoveCategory(GameCategory category)
 {
     return(EngineNetwork.EstablishChannel <IGameService>((service) => {
         return service.RemoveCategory(ActiveGuidGame, category.Name);
     }));
 }