pushing fully working persistence on MAUI
continuous-integration/drone/push Build is passing Details

old_branch_before_remy
Jules LASCRET 11 months ago
parent 3720d4bcfa
commit 612c87e7bf

@ -36,7 +36,9 @@ namespace QwirkleClassLibrary.Games
private readonly Dictionary<string, int> scoreBoard = new Dictionary<string, int>(); private readonly Dictionary<string, int> scoreBoard = new Dictionary<string, int>();
public ReadOnlyDictionary<string, int> ScoreBoard => scoreBoard.AsReadOnly(); public ReadOnlyDictionary<string, int> ScoreBoard => scoreBoard.AsReadOnly();
[DataMember]
private readonly ObservableCollection<KeyValuePair<string, int>> observableScoreBoard = []; private readonly ObservableCollection<KeyValuePair<string, int>> observableScoreBoard = [];
public ReadOnlyObservableCollection<KeyValuePair<string, int>> ObservableScoreBoard => public ReadOnlyObservableCollection<KeyValuePair<string, int>> ObservableScoreBoard =>
new(observableScoreBoard); new(observableScoreBoard);

@ -14,7 +14,9 @@ namespace Qwirkle
{ {
string appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); string appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
string targetPath = Path.Combine(appDataPath, "Programs", "Files"); string targetPath = Path.Combine(appDataPath, "Programs", "Files");
Directory.CreateDirectory(targetPath);
Directory.SetCurrentDirectory(targetPath); Directory.SetCurrentDirectory(targetPath);
InitializeComponent(); InitializeComponent();
MainPage = new AppShell(); MainPage = new AppShell();
@ -27,8 +29,15 @@ namespace Qwirkle
ILeaderboardPersistence leaderboardLoad = new LeaderboardPersistenceJson(); ILeaderboardPersistence leaderboardLoad = new LeaderboardPersistenceJson();
try
{
Ld = leaderboardLoad.LoadLeaderboard(); Ld = leaderboardLoad.LoadLeaderboard();
} }
catch
{
Ld = new Leaderboard();
}
}
public Game Game { get; set; } = new(); public Game Game { get; set; } = new();

@ -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.MainPage" x:Class="Qwirkle.MainPage"
@ -11,22 +12,20 @@
<Label <Label
Text="QWIRKLE" Text="QWIRKLE"
Style="{StaticResource SuperTitle}" Style="{StaticResource SuperTitle}" />
/>
<Image <Image
Source="qwirklelogo.png" Source="qwirklelogo.png"
HeightRequest="300" HeightRequest="300"
Aspect="AspectFit" Aspect="AspectFit" />
/>
<controls:ButtonShadow <controls:ButtonShadow
Text="Play" Text="Play"
InfoClicked="OnInfoClicked" InfoClicked="OnInfoClicked" />
/>
<controls:ButtonShadow Text="Continue"/> <controls:ButtonShadow Text="Continue"
InfoClicked="OnContinueClicked" />
<controls:ButtonShadow Text="Leaderboard" <controls:ButtonShadow Text="Leaderboard"
InfoClicked="OnCLeaderboardClicked" /> InfoClicked="OnCLeaderboardClicked" />

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

@ -30,16 +30,37 @@ public partial class Gameboard : ContentPage
public Color ColorBC3 { get; set; } = Colors.Transparent; public Color ColorBC3 { get; set; } = Colors.Transparent;
public Color ColorBC4 { get; set; } = Colors.Transparent; public Color ColorBC4 { get; set; } = Colors.Transparent;
public Gameboard(string caller)
public Gameboard()
{ {
InitializeComponent(); InitializeComponent();
BindingContext = game; BindingContext = game;
ChangeColorBC(); ChangeColorBC();
if (caller == "ContinueGame")
{
CheckContinuedGame();
}
}
private async void CheckContinuedGame()
{
IGamePersistence gameLoad = new GamePersistenceXml();
try
{
game = gameLoad.LoadGame();
}
catch
{
await DisplayAlert("Error", "No game found", "Got it !");
await Navigation.PopAsync();
}
if (game.GameRunning == false)
{
await DisplayAlert("Error", "No game found", "Got it !");
await Navigation.PopAsync();
}
} }
private async void Game_EndOfGameNotified(object? sender, EndOfGameNotifiedEventArgs e) private async void Game_EndOfGameNotified(object? sender, EndOfGameNotifiedEventArgs e)
@ -235,9 +256,7 @@ public partial class Gameboard : ContentPage
if (answer) if (answer)
{ {
await Navigation.PushAsync(new MainPage()); await Navigation.PopToRootAsync();
} }
} }

@ -32,10 +32,11 @@
Margin="0"> Margin="0">
<Border.GestureRecognizers> <Border.GestureRecognizers>
<DropGestureRecognizer DragOver="OnDragOverBag" <DropGestureRecognizer DragOver="OnDragOverBag"
DropCommand="{Binding OnDropB, Source={x:Reference root}}" DropCommand="{Binding OnDropB, Source={x:Reference root}}" />
/>
</Border.GestureRecognizers> </Border.GestureRecognizers>
<Image Source="bag.png" ToolTipProperties.Text="Pour m'utiliser il faut cliquer sur le boutton swap avant ^^"></Image> <Image Source="bag.png"
ToolTipProperties.Text="Pour m'utiliser il faut cliquer sur le boutton swap avant ^^">
</Image>
</Border> </Border>
<Button <Button
@ -80,8 +81,7 @@
<DataTemplate> <DataTemplate>
<Border WidthRequest="70" HeightRequest="70" <Border WidthRequest="70" HeightRequest="70"
BackgroundColor="{Binding ColorBC1, Source={x:Reference root}}" BackgroundColor="{Binding ColorBC1, Source={x:Reference root}}"
Margin="0" Margin="0">
>
<Border.GestureRecognizers> <Border.GestureRecognizers>
<DragGestureRecognizer CanDrag="True" DragStarting="OnDragStarting" /> <DragGestureRecognizer CanDrag="True" DragStarting="OnDragStarting" />
</Border.GestureRecognizers> </Border.GestureRecognizers>
@ -154,12 +154,13 @@
<ScrollView Grid.Row="1" Grid.Column="1" VerticalOptions="FillAndExpand"> <ScrollView Grid.Row="1" Grid.Column="1" VerticalOptions="FillAndExpand">
<CollectionView ItemsSource="{Binding Board.ReadCells}" <CollectionView ItemsSource="{Binding Board.ReadCells}"
HorizontalOptions="Center" HorizontalOptions="Center"
VerticalOptions="Center" HorizontalScrollBarVisibility="Never" VerticalScrollBarVisibility="Never" VerticalOptions="Center" HorizontalScrollBarVisibility="Never"
> VerticalScrollBarVisibility="Never">
<CollectionView.HeightRequest> <CollectionView.HeightRequest>
<MultiBinding Converter="{StaticResource multiMathExpressionConverter}" ConverterParameter="x0 * x1 +(x0 - 1) * x2 "> <MultiBinding Converter="{StaticResource multiMathExpressionConverter}"
ConverterParameter="x0 * x1 +(x0 - 1) * x2 ">
<Binding Path="Board.Rows" /> <Binding Path="Board.Rows" />
<Binding Source="{StaticResource CellHeight}" /> <Binding Source="{StaticResource CellHeight}" />
<Binding Source="{StaticResource VerticalSpacing}" /> <Binding Source="{StaticResource VerticalSpacing}" />
@ -170,7 +171,8 @@
<CollectionView.WidthRequest> <CollectionView.WidthRequest>
<MultiBinding Converter="{StaticResource multiMathExpressionConverter}" ConverterParameter="x0 * x1 +(x0 - 1) * x2 "> <MultiBinding Converter="{StaticResource multiMathExpressionConverter}"
ConverterParameter="x0 * x1 +(x0 - 1) * x2 ">
<Binding Path="Board.Columns" /> <Binding Path="Board.Columns" />
<Binding Source="{StaticResource CellWidth}" /> <Binding Source="{StaticResource CellWidth}" />
<Binding Source="{StaticResource HorizontalSpacing}" /> <Binding Source="{StaticResource HorizontalSpacing}" />
@ -194,7 +196,9 @@
DropCommand="{Binding OnDrop, Source={x:Reference root}}" DropCommand="{Binding OnDrop, Source={x:Reference root}}"
DropCommandParameter="{Binding .}" /> DropCommandParameter="{Binding .}" />
</Border.GestureRecognizers> </Border.GestureRecognizers>
<controls:TileView HorizontalOptions="Center" Shape="{Binding Tile.GetShape}" Color="{Binding Tile.GetColor}"></controls:TileView> <controls:TileView HorizontalOptions="Center" Shape="{Binding Tile.GetShape}"
Color="{Binding Tile.GetColor}">
</controls:TileView>
</Border> </Border>
</DataTemplate> </DataTemplate>
</CollectionView.ItemTemplate> </CollectionView.ItemTemplate>
@ -204,6 +208,5 @@
<controls:Scoreboard InputTransparent="True" HorizontalOptions="End" Grid.Row="1" Grid.Column="1"></controls:Scoreboard> <controls:Scoreboard InputTransparent="True" HorizontalOptions="End" Grid.Row="1" Grid.Column="1"></controls:Scoreboard>
</Grid> </Grid>
</ContentPage> </ContentPage>

@ -53,7 +53,7 @@ public partial class SetPlayers : ContentPage
game.StartGame(); game.StartGame();
game.GiveTilesToPlayers(); game.GiveTilesToPlayers();
game.SetNextPlayer(); game.SetNextPlayer();
Navigation.PushAsync(new Gameboard()); Navigation.PushAsync(new Gameboard("NewGame"));
} }

Loading…
Cancel
Save