ScoreVM.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. if (App.Game.Players.Count == 1)
  35. return "There is currently " + App.Game.Players.Count + " player in the game.";
  36. else
  37. return "There are currently " + App.Game.Players.Count + " players in the game.";
  38. }
  39. }
  40. }
  41. }