Exemplo n.º 1
0
        private void RecordResult(Difficulty difficulty, int time, bool win)
        {
            PlayerStatsItem item = Stats.Keys.Contains(difficulty) ? Stats[difficulty] : new PlayerStatsItem();

            item.Plays++;
            if (win)
            {
                item.Wins++;
                if (difficulty != Difficulty.Custom &&
                    (item.Fastest == null || item.Fastest > time))
                {
                    // Custom games are not comparable to one another so don't
                    // record the fastest time for that difficulty setting.
                    item.Fastest = time;
                    item.Date    = DateTime.Now.ToUniversalTime();
                }
            }

            Stats[difficulty] = item;
            WriteStats();
        }
Exemplo n.º 2
0
        public PlayerStatsWindow()
        {
            InitializeComponent();

            this.WindowStartupLocation = WindowStartupLocation.CenterOwner;

            this.Closing += playerStatsWindow_Closing;

            for (int i = 0; i < 4; i++)
            {
                Difficulty      difficulty = (Difficulty)i;
                PlayerStatsItem statsItem  = PlayerStatsModel.Stats[difficulty];
                // Get all the stats strings in the order they'll be displayed in the row.
                IList <string> strings = new List <string>()
                {
                    Enum.GetName(typeof(Difficulty), i),              // Difficulty
                    statsItem.Plays.ToString(),                       // Plays
                    statsItem.Wins.ToString(),                        // Wins
                    GetWinPercentage(statsItem),                      // Ratio
                    FormatFastestTime(difficulty, statsItem.Fastest), // Fastest time
                    FormatDate(difficulty, statsItem.Date)            // Date
                };

                for (int j = 0; j < strings.Count; j++)
                {
                    TextBlock textBlock = new TextBlock()
                    {
                        Text = strings[j],
                        HorizontalAlignment = HorizontalAlignment.Left,
                        VerticalAlignment   = VerticalAlignment.Center,
                        Margin = new Thickness(6),
                    };
                    Grid.SetRow(textBlock, i + 1); // Row 0 contains the columns headers so skip it.
                    Grid.SetColumn(textBlock, j);
                    this.statsGrid.Children.Add(textBlock);
                }
            }
        }
Exemplo n.º 3
0
 private string GetWinPercentage(PlayerStatsItem statsItem)
 {
     return(statsItem.Plays == 0
         ? "-"
         : Math.Round((100.0 * statsItem.Wins) / statsItem.Plays, 0).ToString() + "%");
 }