Example #1
0
        public static void AddHighScore(string name, int score)
        {
            if (HighScore.IsTopTen(score) == false)
            {
                return;
            }

            string           outputString = String.Empty;
            List <HighScore> scores       = HighScore.GetAllHighScores();
            string           thisScore    = name + "\t" + score.ToString();

            bool beatPreviousScore = false;
            bool outputtedScore    = false;

            foreach (HighScore s in scores)
            {
                if (s.Score <= score && outputtedScore == false)
                {
                    outputString     += thisScore + Environment.NewLine;
                    beatPreviousScore = true;
                    outputtedScore    = true;
                }
                outputString += s.Name + "\t" + s.Score.ToString() + Environment.NewLine;
            }

            if (!beatPreviousScore && scores.Count < 10 && scores.Count > 0)
            {
                outputString += Environment.NewLine + thisScore;
            }
            else if (!beatPreviousScore && scores.Count < 10 && scores.Count == 0)
            {
                outputString = thisScore;
            }
            File.WriteAllText(OUTPUT_FILE, outputString);
        }
Example #2
0
        private void AddHighScoreForm_Load(object sender, EventArgs e)
        {
            toolStripStatusLabel1.Text = "Your score was " + _score.ToString("N0");
            List <HighScore> scores = HighScore.GetAllHighScores();

            if (scores.Count > 0)
            {
                _txtName.Text = scores[0].Name;
            }
        }
Example #3
0
        public static bool IsTopTen(int score)
        {
            List <HighScore> scores = HighScore.GetAllHighScores();

            if (scores.Count < TOP_SCORES_THAT_MATTER)
            {
                return(true);
            }

            for (int i = 0; i < TOP_SCORES_THAT_MATTER; i++)
            {
                HighScore s = scores[i];
                if (score > s.Score)
                {
                    return(true);
                }
            }
            return(false);
        }
Example #4
0
        private void HighScores_Load(object sender, EventArgs e)
        {
            List <HighScore> scores = HighScore.GetAllHighScores();

            _dgvScores.DataSource = scores;
        }