Exemple #1
0
        /// <summary>
        /// It handles the request by the user to create a new game. If the game was
        /// created, waits for the other player to join. Once joined, terminates the
        /// Matchmaking process and begins the Boggle game.
        /// </summary>
        ///
        /// <param name="serverName">Name of the server</param>
        /// <param name="userName">The player name</param>
        /// <param name="timeLimit">Requested time limit for the game</param>
        private void HandleGameRequest(string serverName, string userName, int timeLimit)
        {
            HandleStatusUpdate("Starting matchmaking...");
            // Create a new Matchmaker and allow it to send back updates along the way
            api = new BoggleApi(serverName, userName, timeLimit);
            api.StatusUpdate += HandleStatusUpdate;

            // Initiate the game request
            int statusCode = api.CreateRequest();

            // If the game was "Created", wait for the other player to join. Once the
            // game is "Accepted", terminate the currently active Matchmaking window and
            // begin the boggle game.
            if ((api.HasCreatedGame && statusCode == 201 && !api.cancel) ||
                (api.HasCreatedGame && statusCode == 202 && !api.cancel))
            {
                dynamic game = api.GetGameRequest();
                if (statusCode == 202 || game.GameState == "pending")
                {
                    // Keep refreshing the game waiting for another player to join
                    while (!api.cancel && game.GameState != "active")
                    {
                        game = api.GetGameRequest();
                    }
                }
                // Don't open the game if we are to cancel.
                if (!api.cancel)
                {
                    BoggleGame newGame = new BoggleGame(game, api.UserName);
                    window.DoClose(newGame);
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Feteches the words played, and opens them in a dialog box.
        /// </summary>
        private void HandleResults()
        {
            BoggleApi api = new BoggleApi(BoggleApi.ServerName, "", 0);

            game.ComputeFinalWordPlayed(api.GetGameRequest());
            window.FinishGame(game);
        }
Exemple #3
0
        /// <summary>
        /// Gets the current status of the game.
        /// </summary>
        /// <returns>The dynamic object for the game.</returns>
        public dynamic RefreshGame()
        {
            BoggleApi api = new BoggleApi(BoggleApi.ServerName, "", 0);

            return(api.GetGameRequest());
        }