Example #1
0
 /// <summary>
 /// Callback implementation to invoke the game window
 /// </summary>
 /// <param name="CBinfo"></param>
 public void UpdateGui(CallbackInfoDC CBinfo)
 {
     try {
         widQuiddler.UpdateGui(CBinfo);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
Example #2
0
 public void UpdateGui(CallbackInfoDC CBinfo)
 {
 }
Example #3
0
        /* ======================================================= */
        /* ================== CALLBACK METHODS =================== */
        /* ======================================================= */
        /// <summary>
        /// Forces a gameover state when the deck runs out of cards
        /// </summary>
        private void forceEndGame()
        {
            try
            {
                logger.logInfo("An end game condition has been forced");

                // Create the callback object
                CallbackInfoDC info = new CallbackInfoDC(getPlayerList(), false, true, false, true, getWinner(false, true), getRoundStatus(true));

                // Update all clients
                foreach (var callback in clients.Values)
                {
                    callback.UpdateGui(info);
                }
            }
            catch (Exception ex)
            {
                logger.logError(ex.Message);
                throw ex;
            }
        }
Example #4
0
        /// <summary>
        /// Update all connected clients with the current game's state
        /// </summary>
        /// <param name="startGame"></param>
        /// <param name="endGame"></param>
        private void updateAllClients(bool startGame, bool endGame)
        {
            try
            {
                // Dynamically changing state variables
                bool gameState = false;
                bool readyState = false;
                bool waiting = false;

                // Starting a new game
                if (startGame)
                {
                    logger.logInfo("Starting the game");

                    // Indicate game is running
                    gameInProgress = true;

                    // Clear/Increment round count
                    roundCount = 1;

                    // Reset user values
                    foreach (UserDC user in users.Values)
                    {
                        user.Score = 0;
                        user.isReady = false;
                        user.turnEnded = false;
                    }

                    // Enable all users to play
                    gameState = true;
                    readyState = false;
                }

                // Starting a new round
                else if (readyForNewRound())
                {
                    logger.logInfo("Beginning a new round");

                    // Reset user's turn
                    foreach (UserDC user in users.Values)
                    {
                        user.turnEnded = false;
                    }

                    // Enable all users to play
                    gameState = true;
                    readyState = false;

                    // Increment the rount count
                    roundCount++;

                    // Re-evaluate end game status
                    endGame = !(roundCount <= settings.RoundCount);
                }
                // Waiting to start a new game
                else if (!gameInProgress)
                {
                    readyState = true;
                }
                // Ending the game
                if (endGame)
                {
                    logger.logInfo("Ending the game");

                    // Indicate game has ended
                    gameInProgress = false;

                    // Disable all users from playing
                    gameState = false;
                    readyState = true;
                }
                // Waiting for other players
                else
                {
                    waiting = true;
                }

                // Process statistics
                string[] players = getPlayerList();
                string winner = getWinner(endGame, false);

                // Waiting for other users
                if (waiting)
                {
                    // Update all clients (user specific callback)
                    foreach (var cb in clients)
                    {
                        cb.Value.UpdateGui(new CallbackInfoDC(players, startGame, endGame, !(users[cb.Key].turnEnded), readyState, winner, getRoundStatus(endGame)));
                    }
                }
                // All users ready
                else
                {
                    // Create the callback object
                    CallbackInfoDC info = new CallbackInfoDC(players, startGame, endGame, gameState, readyState, winner, getRoundStatus(endGame));

                    // Update all clients
                    foreach (var callback in clients.Values)
                    {
                        callback.UpdateGui(info);
                    }
                }
            }
            catch (Exception ex)
            {
                logger.logError(ex.Message);
                throw ex;
            }
        }
Example #5
0
        public void UpdateGui(CallbackInfoDC info)
        {
            if (System.Threading.Thread.CurrentThread == this.Dispatcher.Thread)
            {
                try
                {
                    // Update user count
                    txtNumUsers.Text = info.usersLst.Length.ToString();

                    // Update round
                    lblRound.Content = "Round: " + info.roundStatus;

                    // Update user list (names & scores)
                    lstPlayers.Items.Clear();
                    foreach (string user in info.usersLst)
                    {
                        lstPlayers.Items.Add(user);
                    }

                    // User joined the game
                    if (userCount < info.usersLst.Length)
                    {
                        // Update count
                        userCount = info.usersLst.Length;

                        // Play sound
                        sounds.Play("user_joined");
                    }
                    // User left the game
                    else if (userCount > info.usersLst.Length)
                    {
                        // Update count
                        userCount = info.usersLst.Length;

                        //Play sound
                        sounds.Play("user_left");
                    }

                    // Starting a new game
                    if (info.startGame)
                    {
                        lblEndGameMsg.Visibility = Visibility.Hidden;
                        txtBoxStatus.Text = "";
                        getCards(true);
                    }
                    // Ending the current game
                    else if (info.endGame)
                    {
                        lblEndGameMsg.Content = info.endGameMsg;
                        scaleText(lblEndGameMsg);
                        lblEndGameMsg.Visibility = Visibility.Visible;

                        // Play sound
                        sounds.Stop("user_scored");
                        sounds.PlaySync("game_over");
                    }

                    // Enable/Disable game controls
                    GamePlayable(info.gameState, info.readyState);

                    // Hide waiting condition (Endgame Override)
                    if (info.endGame)
                    {
                        lblWaiting.Visibility = Visibility.Hidden;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            else
            {
                // Only the main dispatcher thread can change the GUI
                this.Dispatcher.BeginInvoke(new ClientUpdateDelegate(UpdateGui), info);
            }
        }