ScoreVM.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using YJMPD_UWP.Model.Object;
  4. namespace YJMPD_UWP.ViewModels
  5. {
  6. public class ScoreVM : TemplateVM
  7. {
  8. private List<Player> players;
  9. public ScoreVM() : base("Scores")
  10. {
  11. this.players = App.Game.Players.OrderBy(p => p.Points).ToList();
  12. App.Game.OnPlayersUpdate += Game_OnPlayersUpdate;
  13. }
  14. private void Game_OnPlayersUpdate(object sender, Helpers.EventArgs.GamePlayersUpdatedEventArgs e)
  15. {
  16. dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
  17. {
  18. this.players = App.Game.Players.OrderBy(p => p.Points).ToList();
  19. NotifyPropertyChanged(nameof(Players));
  20. NotifyPropertyChanged(nameof(PlayersCount));
  21. });
  22. }
  23. public List<Player> Players
  24. {
  25. get
  26. {
  27. return new List<Player>(players);
  28. }
  29. }
  30. public string PlayersCount
  31. {
  32. get
  33. {
  34. return "There are currently " + App.Game.Players.Count + " players in the match.";
  35. }
  36. }
  37. }
  38. }