ScoreVM.cs 1.2 KB

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