コード例 #1
0
        /// <summary>
        /// Updates the statistics based on a won game.
        /// </summary>
        /// <param name="cardGame">The card game.</param>
        public void UpdateStatistics(CardGameViewModel cardGame)
        {
            //  Update the games won or lost.
            GamesPlayed++;
            if (cardGame.IsGameWon)
            {
                GamesWon++;
            }
            else
            {
                GamesLost++;
            }

            //  Update the current streak.
            if (cardGame.IsGameWon)
            {
                CurrentStreak = CurrentStreak < 0 ? 1 : CurrentStreak + 1;
            }
            else
            {
                CurrentStreak = CurrentStreak > 0 ? -1 : CurrentStreak - 1;
            }

            //  Update the highest streaks.
            if (CurrentStreak > HighestWinningStreak)
            {
                HighestWinningStreak = CurrentStreak;
            }
            else if (Math.Abs(CurrentStreak) > HighestLosingStreak)
            {
                HighestLosingStreak = Math.Abs(CurrentStreak);
            }

            //  Update the highest score.
            if (cardGame.Score > HighestScore)
            {
                HighestScore = cardGame.Score;
            }

            //  Update the average score. Only won games
            //  contribute to the running average.
            if (cardGame.IsGameWon)
            {
                CumulativeScore += cardGame.Score;
                AverageScore     = CumulativeScore / GamesWon;
            }

            //  Update the average game time.
            CumulativeGameTime += cardGame.ElapsedTime;
            AverageGameTime     = TimeSpan.FromTicks(CumulativeGameTime.Ticks / (GamesWon + GamesLost));
        }
コード例 #2
0
ファイル: GameStatistics.cs プロジェクト: embix/WpfSolitaire
        /// <summary>
        /// Updates the statistics based on a won game.
        /// </summary>
        /// <param name="cardGame">The card game.</param>
        public void UpdateStatistics(CardGameViewModel cardGame)
        {
            //  Update the games won or lost.
            GamesPlayed++;
            if (cardGame.IsGameWon)
                GamesWon++;
            else
                GamesLost++;

            //  Update the current streak.
            if (cardGame.IsGameWon)
                CurrentStreak = CurrentStreak < 0 ? 1 : CurrentStreak + 1;
            else
                CurrentStreak = CurrentStreak > 0 ? -1 : CurrentStreak - 1;

            //  Update the highest streaks.
            if (CurrentStreak > HighestWinningStreak)
                HighestWinningStreak = CurrentStreak;
            else if (Math.Abs(CurrentStreak) > HighestLosingStreak)
                HighestLosingStreak = Math.Abs(CurrentStreak);

            //  Update the highest score.
            if (cardGame.Score > HighestScore)
                HighestScore = cardGame.Score;

            //  Update the average score. Only won games
            //  contribute to the running average.
            if (cardGame.IsGameWon)
            {
                CumulativeScore += cardGame.Score;
                AverageScore = CumulativeScore / GamesWon;
            }

            //  Update the average game time.
            CumulativeGameTime += cardGame.ElapsedTime;
            AverageGameTime = TimeSpan.FromTicks(CumulativeGameTime.Ticks / (GamesWon + GamesLost));
        }