Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Plays the passed word.
        /// </summary>
        /// <param name="word">Word to be played</param>
        /// <returns>The score of the word play</returns>
        public int PlayWord(string word)
        {
            // username and time limit is not required when playing a word.
            BoggleApi api   = new BoggleApi(BoggleApi.ServerName, "", 0);
            int       score = api.PlayWord(word);

            HomePlayer.Score += score;
            return(score);
        }
Ejemplo n.º 4
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());
        }