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.
57 lines
1.6 KiB
57 lines
1.6 KiB
using QwirkleClassLibrary.Players;
|
|
using System.Collections.ObjectModel;
|
|
using System.ComponentModel;
|
|
|
|
namespace Qwirkle.Views;
|
|
|
|
public partial class Scoreboard : ContentView, INotifyPropertyChanged
|
|
{
|
|
private IOrderedEnumerable<KeyValuePair<Player, int>> scoreboard;
|
|
private Dictionary<Player, int> currentScoreBoard;
|
|
|
|
private List<Player> namesPlayers;
|
|
public List<Player> NamesPlayers
|
|
{
|
|
get => namesPlayers;
|
|
set
|
|
{
|
|
if (namesPlayers != value)
|
|
{
|
|
namesPlayers = value;
|
|
OnPropertyChanged(nameof(NamesPlayers));
|
|
}
|
|
}
|
|
}
|
|
public Scoreboard()
|
|
{
|
|
InitializeComponent();
|
|
BindingContext = this;
|
|
|
|
scoreboard = ((App)Application.Current!).Game.ScoreBoard.OrderByDescending(x => x.Value).ThenBy(x => x.Key.NameTag);
|
|
currentScoreBoard = scoreboard.ToDictionary<Player, int>();
|
|
|
|
NamesPlayers = currentScoreBoard.Keys.ToList();
|
|
|
|
((App)Application.Current!).Game.Board.PropertyChanged += Board_PropertyChanged;
|
|
}
|
|
|
|
private void Board_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
|
|
{
|
|
|
|
scoreboard = ((App)Application.Current!).Game.ScoreBoard.OrderByDescending(x => x.Value).ThenBy(x => x.Key.NameTag);
|
|
currentScoreBoard = scoreboard.ToDictionary<Player, int>();
|
|
|
|
NamesPlayers = currentScoreBoard.Keys.ToList();
|
|
|
|
}
|
|
|
|
public event PropertyChangedEventHandler? PropertyChanged;
|
|
|
|
protected void OnPropertyChanged(string propertyName)
|
|
{
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
}
|
|
|
|
|
|
|
|
} |