diff --git a/Qwirkle/QwirkleClassLibrary/Players/Leaderboard.cs b/Qwirkle/QwirkleClassLibrary/Players/Leaderboard.cs index 8d40223..d85d4ee 100644 --- a/Qwirkle/QwirkleClassLibrary/Players/Leaderboard.cs +++ b/Qwirkle/QwirkleClassLibrary/Players/Leaderboard.cs @@ -16,7 +16,7 @@ namespace QwirkleClassLibrary.Players public class Leaderboard : INotifyPropertyChanged { [DataMember] - private readonly ObservableCollection leaderboard = new(); + private ObservableCollection leaderboard = new(); public event PropertyChangedEventHandler? PropertyChanged; @@ -26,12 +26,7 @@ namespace QwirkleClassLibrary.Players } public ReadOnlyObservableCollection Lb => new(leaderboard); - - - - - - + /// /// Returns the index of the player in the leaderboard, -1 if the player is not in the leaderboard /// @@ -96,6 +91,7 @@ namespace QwirkleClassLibrary.Players first = false; } + leaderboard = new ObservableCollection(leaderboard.OrderByDescending(x => x.Points).ThenBy(x => x.Victories)); } } } diff --git a/Qwirkle/QwirkleViews/App.xaml.cs b/Qwirkle/QwirkleViews/App.xaml.cs index 12606b5..5a8252b 100644 --- a/Qwirkle/QwirkleViews/App.xaml.cs +++ b/Qwirkle/QwirkleViews/App.xaml.cs @@ -2,7 +2,9 @@ using Microsoft.Maui.Controls; using Qwirkle.Pages; using QwirkleClassLibrary.Games; +using QwirkleClassLibrary.Persistences; using QwirkleClassLibrary.Players; +using Leaderboard = QwirkleClassLibrary.Players.Leaderboard; namespace Qwirkle { @@ -10,6 +12,7 @@ namespace Qwirkle { public App() { + Directory.SetCurrentDirectory(Path.Combine(Directory.GetCurrentDirectory(), "..\\..\\..\\Files")); InitializeComponent(); MainPage = new AppShell(); @@ -20,10 +23,12 @@ namespace Qwirkle Routing.RegisterRoute(nameof(MainPage), typeof(MainPage)); Routing.RegisterRoute(nameof(Qwirkle.Pages.Leaderboard), typeof(Qwirkle.Pages.Leaderboard)); + ILeaderboardPersistence leaderboardLoad = new LeaderboardPersistenceJson(); + Ld = leaderboardLoad.LoadLeaderboard(); } + public Game Game { get; set; } = new(); - public QwirkleClassLibrary.Players.Leaderboard LD { get; set; } = new(); - + public Leaderboard Ld { get; set; } } } diff --git a/Qwirkle/QwirkleViews/MainPage.xaml b/Qwirkle/QwirkleViews/MainPage.xaml index 607867c..c8eb72a 100644 --- a/Qwirkle/QwirkleViews/MainPage.xaml +++ b/Qwirkle/QwirkleViews/MainPage.xaml @@ -6,7 +6,7 @@ - + \ No newline at end of file diff --git a/Qwirkle/QwirkleViews/Pages/Leaderboard.xaml.cs b/Qwirkle/QwirkleViews/Pages/Leaderboard.xaml.cs index 85be440..83f3139 100644 --- a/Qwirkle/QwirkleViews/Pages/Leaderboard.xaml.cs +++ b/Qwirkle/QwirkleViews/Pages/Leaderboard.xaml.cs @@ -5,6 +5,6 @@ public partial class Leaderboard : ContentPage public Leaderboard() { InitializeComponent(); - BindingContext = ((App)Application.Current!).LD; + BindingContext = ((App)Application.Current!).Ld; } } \ No newline at end of file diff --git a/Qwirkle/TestBase/TestLeaderboard.cs b/Qwirkle/TestBase/TestLeaderboard.cs index ee860c5..6c0d9fe 100644 --- a/Qwirkle/TestBase/TestLeaderboard.cs +++ b/Qwirkle/TestBase/TestLeaderboard.cs @@ -50,8 +50,6 @@ public class TestLeaderboard leaderboard.AddScoreInLead(game.ScoreBoard); - var game2 = new Game(); - game.AddPlayerInGame(playerstest); game.StartGame(); @@ -61,7 +59,7 @@ public class TestLeaderboard leaderboard.AddScoreInLead(game.ScoreBoard); - Assert.Equal(2, leaderboard.Lb[0].Victories); + Assert.Equal(2, leaderboard.Lb[1].Victories); }