You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
sae201_qwirkle/Qwirkle/QwirkleViews/Views/Scoreboard.xaml.cs

52 lines
1.6 KiB

using QwirkleClassLibrary.Players;
using QwirkleClassLibrary.Games;
using QwirkleClassLibrary.Boards;
using System.Collections.ObjectModel;
using System.ComponentModel;
namespace Qwirkle.Views;
public partial class Scoreboard : ContentView, INotifyPropertyChanged
{
private Game game = ((App)Application.Current!).Game;
private IOrderedEnumerable<KeyValuePair<string, int>> scoreboard;
private ObservableCollection<KeyValuePair<string, int>> scoreboardList;
public ObservableCollection<KeyValuePair<string, int>> ScoreboardList
{
get => scoreboardList;
set
{
if (scoreboardList != value)
{
scoreboardList = value;
OnPropertyChanged(nameof(ScoreboardList));
}
}
}
public Scoreboard()
{
InitializeComponent();
BindingContext = this;
scoreboard = game.ScoreBoard.OrderByDescending(x => x.Value).ThenBy(x => x.Key);
ScoreboardList = new ObservableCollection<KeyValuePair<string, int>>(scoreboard);
game.Board.PropertyChanged += Board_PropertyChanged;
}
private void Board_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
{
scoreboard = game.ScoreBoard.OrderByDescending(x => x.Value).ThenBy(x => x.Key.NameTag);
ScoreboardList = new ObservableCollection<KeyValuePair<string, int>>(scoreboard);
}
public event PropertyChangedEventHandler? PropertyChanged;
protected void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}