示例#1
0
        private static void WriteResults(IScoreTracker result)
        {
            //Assign calculated results to ScoreBoardStats class:
            ScoreBoardStats playerStats = result.CalculateScoreBoardStats();

            //Display results:
            WriteResult("The Highest Score is: ", playerStats.HighestScore);
            WriteResult("The Lowest Score is: ", playerStats.LowestScore);
            WriteResult("The Average Score is: ", playerStats.AverageScore);
            //Display the players Skill level:
            WriteResult("Your Skill Level is: ", playerStats.PlayerSkill);
        }
示例#2
0
        //Method to calculate stats:
        public override ScoreBoardStats CalculateScoreBoardStats()
        //made virtual so that derived class (ThrowAwayPlayerScore) can change method
        {
            ScoreBoardStats stats = new ScoreBoardStats();

            //Calculate the Average, Highest & Lowest stats:
            float sum = 0;

            foreach (float score in scores)
            {
                stats.HighestScore = Math.Max(score, stats.HighestScore); //Highest calculated
                stats.LowestScore  = Math.Min(score, stats.LowestScore);  //Lowest calculated
                sum += score;
            }
            stats.AverageScore = sum / scores.Count; // Average calculated

            return(stats);
        }