示例#1
0
        /// <summary>
        /// Populates the page with content passed during navigation.  Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="navigationParameter">The parameter value passed to
        /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested.
        /// </param>
        /// <param name="pageState">A dictionary of state preserved by this page during an earlier
        /// session.  This will be null the first time a page is visited.</param>
        private void LoadState(Object navigationParameter, Dictionary <String, Object> pageState)
        {
            ScorePageParameters parameters = (ScorePageParameters)navigationParameter;

            gameScore = parameters.Score;
            gameMode  = parameters.GameMode;

            if (gameMode == Constants.SinglePlayer)
            {
                finalScoreDisplay.Text = "You scored " + parameters.Score.ToString();
                progressBar.Visibility = Visibility.Collapsed;
            }
            else
            {
                // Each player starts with an empty list of scores
                // Hosts populate their lists as they receive scores
                // Clients populate their lists when the host sends them scores
                playerScores = new Dictionary <string, string>();

                connectedPeers = parameters.ConnectedPeers;

                foreach (ConnectedPeer peer in connectedPeers.Keys)
                {
                    try
                    {
                        // Set each socket's current page to ScorePage.
                        connectedPeers[peer].currentPage = this;
                        connectedPeers[peer].UpdateCurrentPageType();

                        if (gameMode != Constants.SinglePlayer)
                        {
                            if (PeerFinder.Role == PeerRole.Client)
                            {
                                socket = connectedPeers[peer];
                            }
                            else if (PeerFinder.Role == PeerRole.Host)
                            {
                                numPlayers    = connectedPeers.Count + 1;
                                closedSockets = 0;
                                playerScores[PeerFinder.DisplayName] = gameScore.ToString();
                                connectedPeers[peer].WriteMessage(Message.Navigated);
                            }
                        }
                    }
                    catch (Exception err)
                    {
                        infoText.Text += "\nError loading scores: \n" + err.ToString();
                    }
                }
            }
        }
        public void NavigateToScorePage()
        {
            try
            {
                gameTimer.Stop();

                ScorePageParameters parameters = new ScorePageParameters()
                {
                    Score          = gameScore,
                    ConnectedPeers = connectedPeers,
                    GameMode       = gameMode
                };

                Frame.Navigate(typeof(ScorePage), parameters);
            }
            catch (Exception err)
            {
                scoreText.Text = "Error navigating: " + err.ToString();
            }
        }
        public void NavigateToScorePage()
        {
            try
            {
                gameTimer.Stop();

                ScorePageParameters parameters = new ScorePageParameters()
                {
                    Score = gameScore,
                    ConnectedPeers = connectedPeers,
                    GameMode = gameMode
                };

                Frame.Navigate(typeof(ScorePage), parameters);
            }
            catch (Exception err)
            {
                scoreText.Text = "Error navigating: " + err.ToString();
            }
        }