Merge branch 'master' of https://codefirst.iut.uca.fr/git/jeremy.mouyon/sae201_qwirkle
continuous-integration/drone/push Build is passing Details

old_branch_before_remy
Jérémy Mouyon 11 months ago
commit ba1bc3e07f

@ -16,7 +16,7 @@ namespace QwirkleClassLibrary.Players
public class Leaderboard : INotifyPropertyChanged public class Leaderboard : INotifyPropertyChanged
{ {
[DataMember] [DataMember]
private readonly ObservableCollection<Score> leaderboard = new(); private ObservableCollection<Score> leaderboard = new();
public event PropertyChangedEventHandler? PropertyChanged; public event PropertyChangedEventHandler? PropertyChanged;
@ -27,11 +27,6 @@ namespace QwirkleClassLibrary.Players
public ReadOnlyObservableCollection<Score> Lb => new(leaderboard); public ReadOnlyObservableCollection<Score> Lb => new(leaderboard);
/// <summary> /// <summary>
/// Returns the index of the player in the leaderboard, -1 if the player is not in the leaderboard /// Returns the index of the player in the leaderboard, -1 if the player is not in the leaderboard
/// </summary> /// </summary>
@ -96,6 +91,7 @@ namespace QwirkleClassLibrary.Players
first = false; first = false;
} }
leaderboard = new ObservableCollection<Score>(leaderboard.OrderByDescending(x => x.Points).ThenBy(x => x.Victories));
} }
} }
} }

@ -2,7 +2,9 @@
using Microsoft.Maui.Controls; using Microsoft.Maui.Controls;
using Qwirkle.Pages; using Qwirkle.Pages;
using QwirkleClassLibrary.Games; using QwirkleClassLibrary.Games;
using QwirkleClassLibrary.Persistences;
using QwirkleClassLibrary.Players; using QwirkleClassLibrary.Players;
using Leaderboard = QwirkleClassLibrary.Players.Leaderboard;
namespace Qwirkle namespace Qwirkle
{ {
@ -10,6 +12,7 @@ namespace Qwirkle
{ {
public App() public App()
{ {
Directory.SetCurrentDirectory(Path.Combine(Directory.GetCurrentDirectory(), "..\\..\\..\\Files"));
InitializeComponent(); InitializeComponent();
MainPage = new AppShell(); MainPage = new AppShell();
@ -20,10 +23,12 @@ namespace Qwirkle
Routing.RegisterRoute(nameof(MainPage), typeof(MainPage)); Routing.RegisterRoute(nameof(MainPage), typeof(MainPage));
Routing.RegisterRoute(nameof(Qwirkle.Pages.Leaderboard), typeof(Qwirkle.Pages.Leaderboard)); 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 Game Game { get; set; } = new();
public Leaderboard Ld { get; set; }
} }
} }

@ -6,7 +6,7 @@
<ScrollView> <ScrollView>
<VerticalStackLayout <VerticalStackLayout
Padding="30,0" Padding="30, 0, 30, 30"
Spacing="25"> Spacing="25">
<Label <Label
@ -26,6 +26,8 @@
InfoClicked="OnInfoClicked" InfoClicked="OnInfoClicked"
/> />
<controls:ButtonShadow Text="Continue"/>
<controls:ButtonShadow Text="Leaderboard" <controls:ButtonShadow Text="Leaderboard"
InfoClicked="OnCLeaderboardClicked"/> InfoClicked="OnCLeaderboardClicked"/>

@ -22,7 +22,6 @@ namespace Qwirkle
Navigation.PushAsync(new SetPlayers()); Navigation.PushAsync(new SetPlayers());
} }
public void OnRulesClicked(object sender, EventArgs e) public void OnRulesClicked(object sender, EventArgs e)
{ {
Navigation.PushAsync(new Rules()); Navigation.PushAsync(new Rules());

@ -9,6 +9,7 @@ using System.ComponentModel;
using Cell = QwirkleClassLibrary.Boards.Cell; using Cell = QwirkleClassLibrary.Boards.Cell;
using Color = Microsoft.Maui.Graphics.Color; using Color = Microsoft.Maui.Graphics.Color;
using System.Drawing; using System.Drawing;
using QwirkleClassLibrary.Persistences;
using CommunityToolkit.Maui.Views; using CommunityToolkit.Maui.Views;
namespace Qwirkle.Pages; namespace Qwirkle.Pages;
@ -112,6 +113,11 @@ public partial class Gameboard : ContentPage
game.DrawTiles(game.GetPlayingPlayer()); game.DrawTiles(game.GetPlayingPlayer());
} }
game.CheckGameOver(game.GetPlayingPlayer());
IGamePersistence gameIntermediateSave = new GamePersistenceXml();
gameIntermediateSave.SaveGame(game);
if (!game.CheckGameOver(game.GetPlayingPlayer())) if (!game.CheckGameOver(game.GetPlayingPlayer()))
{ {
game.SetNextPlayer(); game.SetNextPlayer();
@ -119,7 +125,14 @@ public partial class Gameboard : ContentPage
} }
else else
{ {
((App)Application.Current!).LD.AddScoreInLead(game.ScoreBoard); ((App)Application.Current!).Ld.AddScoreInLead(game.ScoreBoard);
IGamePersistence gameEndSave = new GamePersistenceXml();
gameEndSave.SaveGame(game);
ILeaderboardPersistence leaderboardSave = new LeaderboardPersistenceJson();
leaderboardSave.SaveLeaderboard(((App)Application.Current!).Ld);
game.ClearGame(); game.ClearGame();
} }
game.NextPlayerNotified -= Game_NextPlayerNotified; game.NextPlayerNotified -= Game_NextPlayerNotified;

@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8"?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Qwirkle.Pages.Leaderboard" x:Class="Qwirkle.Pages.Leaderboard"
@ -11,16 +12,16 @@
<Grid Style="{StaticResource GridMain}"> <Grid Style="{StaticResource GridMain}">
<controls:GoBack></controls:GoBack> <controls:GoBack></controls:GoBack>
<Label Text="Leaderboard" <Label Text="Leaderboard"
Style="{StaticResource Title}"/> Style="{StaticResource Title}" />
</Grid> </Grid>
<Border Style="{StaticResource TabBorder}"> <Border Style="{StaticResource TabBorder}">
<Border.Shadow> <Border.Shadow>
<Shadow/> <Shadow />
</Border.Shadow> </Border.Shadow>
<Border.StrokeShape> <Border.StrokeShape>
<RoundRectangle CornerRadius="3"/> <RoundRectangle CornerRadius="3" />
</Border.StrokeShape> </Border.StrokeShape>
<StackLayout> <StackLayout>
@ -28,37 +29,38 @@
RowDefinitions="50"> RowDefinitions="50">
<Label <Label
Text="Player tag" Text="Player tag"
Style="{StaticResource ContentTab}"/> Style="{StaticResource ContentTab}" />
<Rectangle <Rectangle
Style="{StaticResource RectangleTab}" Style="{StaticResource RectangleTab}"
Grid.Column="1"/> Grid.Column="1" />
<Label <Label
Grid.Column="2" Grid.Column="2"
Text="Date" Text="Date"
Style="{StaticResource ContentTab}"/> Style="{StaticResource ContentTab}" />
<Rectangle <Rectangle
Style="{StaticResource RectangleTab}" Style="{StaticResource RectangleTab}"
Grid.Column="3"/> Grid.Column="3" />
<Label <Label
Grid.Column="4" Grid.Column="4"
Text="Points" Text="Points"
Style="{StaticResource ContentTab}"/> Style="{StaticResource ContentTab}" />
<Rectangle <Rectangle
Style="{StaticResource RectangleTab}" Style="{StaticResource RectangleTab}"
Grid.Column="5"/> Grid.Column="5" />
<Label <Label
Grid.Column="6" Grid.Column="6"
Style="{StaticResource ContentTab}" Style="{StaticResource ContentTab}"
Text="Victories"/> Text="Victories" />
</Grid> </Grid>
<CollectionView ItemsSource="{Binding Lb}"> <CollectionView ItemsSource="{Binding Lb}">
<CollectionView.ItemsLayout> <CollectionView.ItemsLayout>
<GridItemsLayout Orientation="Vertical"/> <GridItemsLayout Orientation="Vertical" />
</CollectionView.ItemsLayout> </CollectionView.ItemsLayout>
<CollectionView.ItemTemplate> <CollectionView.ItemTemplate>
<DataTemplate> <DataTemplate>
<controls:LeaderboardLine PlayerName="{Binding PlayerName}" Date="{Binding Date}" Points="{Binding Points}" Victories="{Binding Victories}" /> <controls:LeaderboardLine PlayerName="{Binding PlayerName}" Date="{Binding Date}"
Points="{Binding Points}" Victories="{Binding Victories}" />
</DataTemplate> </DataTemplate>
</CollectionView.ItemTemplate> </CollectionView.ItemTemplate>
</CollectionView> </CollectionView>

@ -5,6 +5,6 @@ public partial class Leaderboard : ContentPage
public Leaderboard() public Leaderboard()
{ {
InitializeComponent(); InitializeComponent();
BindingContext = ((App)Application.Current!).LD; BindingContext = ((App)Application.Current!).Ld;
} }
} }

@ -50,8 +50,6 @@ public class TestLeaderboard
leaderboard.AddScoreInLead(game.ScoreBoard); leaderboard.AddScoreInLead(game.ScoreBoard);
var game2 = new Game();
game.AddPlayerInGame(playerstest); game.AddPlayerInGame(playerstest);
game.StartGame(); game.StartGame();
@ -61,7 +59,7 @@ public class TestLeaderboard
leaderboard.AddScoreInLead(game.ScoreBoard); leaderboard.AddScoreInLead(game.ScoreBoard);
Assert.Equal(2, leaderboard.Lb[0].Victories); Assert.Equal(2, leaderboard.Lb[1].Victories);
} }

Loading…
Cancel
Save