Exemple #1
0
        public StatsForm()
        {
            InitializeComponent();

            lbl_stats_display.Size = new Size(panel1.Width, 1200);

            SneezeDatabase database = SneezeClientListener.Database;

            streakMap            = database.FindLongestStreaks();
            streakCountToUserMap = database.FindAllStreaks();
            userStats            = database.FindUserStats();
            font           = lbl_stats_display.Font;
            headingFont    = new Font(lbl_stats_display.Font.FontFamily, lbl_stats_display.Font.Size * 1.5f, FontStyle.Bold);
            subheadingFont = new Font(lbl_stats_display.Font, FontStyle.Bold);
        }
        private string GetLongestStreak()
        {
            SneezeDatabase database = SneezeClientListener.Database;

            if (database.Sneezes.Count == 0 || CurrentUser.UserGuid == CommonInfo.UnknownUserId)
            {
                return("");
            }

            Dictionary <Guid, int> streaks = database.FindLongestStreaks();
            int  longestStreak             = 0;
            Guid streakWinnerId            = database.Sneezes[0].UserId; //The first person to reach the longest streak is the winner if there is a tie

            foreach (KeyValuePair <Guid, int> streak in streaks)
            {
                if (streak.Value > longestStreak)
                {
                    longestStreak  = streak.Value;
                    streakWinnerId = streak.Key;
                }
            }

            int currentStreak = 1;
            int index         = 1;

            while (index <= database.Sneezes.Count && database.Sneezes[database.Sneezes.Count - index].UserId == CurrentUser.UserGuid)
            {
                index++;
                currentStreak++;
            }

            int    sneezesToVictory = longestStreak + 1 - currentStreak; //I definitely need to calculate the current streak rather than using 1
            string retStr           = "";


            if (currentStreak == 3 && CurrentUser.UserGuid != streakWinnerId && sneezesToVictory > 1)
            {
                retStr = String.Format("The person with the longest streak is {0} with {1} sneezes.\nYou need to sneeze {2} times in order to beat {0}.", database.IdToUser[streakWinnerId].Name, longestStreak, sneezesToVictory);
            }
            else if (sneezesToVictory == 1)
            {
                retStr = String.Format("Way to go!\nYou are only ONE sneeze away from breaking the sneeze streak record which is currently held by {0}.", database.IdToUser[streakWinnerId].Name);
            }
            else if (sneezesToVictory == 0)
            {
                if (CurrentUser.UserGuid != streakWinnerId)
                {
                    retStr = String.Format("!!! Congratulations {0} !!! \nYou set a new record for the longest sneeze streak!\nYour {1} sneeze streak beat {2}'s {3} sneeze streak.", CurrentUser.Name, currentStreak, SneezeClientListener.Database.IdToUser[streakWinnerId].Name, longestStreak);
                    if (!String.IsNullOrEmpty(txtbx_commentary.Text))
                    {
                        txtbx_commentary.Text += "\n";
                    }
                    txtbx_commentary.Text += String.Format("{0} beat {1}'s sneeze streak record.", CurrentUser.Name, database.IdToUser[streakWinnerId].Name);
                }
                else
                {
                    retStr = String.Format("!!! Congratulations {0} !!! \nYou have become a sneezing legend!\nYou have increased your lead and set a new sneeze streak record!", CurrentUser.Name);
                    if (!String.IsNullOrEmpty(txtbx_commentary.Text))
                    {
                        txtbx_commentary.Text += "\n";
                    }
                    txtbx_commentary.Text += "The legend continues!";
                }
            }
            return(retStr);
        }