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>();
public ReadOnlyDictionary<string, int> ScoreBoard => scoreBoard.AsReadOnly();
[DataMember]
private readonly ObservableCollection<KeyValuePair<string, int>> observableScoreBoard = [];
public ReadOnlyObservableCollection<KeyValuePair<string, int>> ObservableScoreBoard =>
new(observableScoreBoard);

@ -14,7 +14,9 @@ namespace Qwirkle
{
string appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
string targetPath = Path.Combine(appDataPath, "Programs", "Files");
Directory.CreateDirectory(targetPath);
Directory.SetCurrentDirectory(targetPath);
InitializeComponent();
MainPage = new AppShell();
@ -26,8 +28,15 @@ namespace Qwirkle
Routing.RegisterRoute(nameof(Qwirkle.Pages.Leaderboard), typeof(Qwirkle.Pages.Leaderboard));
ILeaderboardPersistence leaderboardLoad = new LeaderboardPersistenceJson();
Ld = leaderboardLoad.LoadLeaderboard();
try
{
Ld = leaderboardLoad.LoadLeaderboard();
}
catch
{
Ld = new Leaderboard();
}
}

@ -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"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Qwirkle.MainPage"
@ -11,38 +12,36 @@
<Label
Text="QWIRKLE"
Style="{StaticResource SuperTitle}"
/>
Style="{StaticResource SuperTitle}" />
<Image
Source="qwirklelogo.png"
HeightRequest="300"
Aspect="AspectFit"
/>
Aspect="AspectFit" />
<controls:ButtonShadow
<controls:ButtonShadow
Text="Play"
InfoClicked="OnInfoClicked"
/>
<controls:ButtonShadow Text="Continue"/>
InfoClicked="OnInfoClicked" />
<controls:ButtonShadow Text="Continue"
InfoClicked="OnContinueClicked" />
<controls:ButtonShadow Text="Leaderboard"
InfoClicked="OnCLeaderboardClicked"/>
InfoClicked="OnCLeaderboardClicked" />
<controls:ButtonShadow Text="Rules"
InfoClicked="OnRulesClicked"/>
InfoClicked="OnRulesClicked" />
<controls:ButtonShadow Text="Settings"
InfoClicked="OnSettingsClicked"/>
InfoClicked="OnSettingsClicked" />
<controls:ButtonShadow Text="Credits"
InfoClicked="OnCreditsClicked"/>
InfoClicked="OnCreditsClicked" />
</VerticalStackLayout>
</ScrollView>
</ContentPage>
</ContentPage>

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

@ -30,18 +30,39 @@ public partial class Gameboard : ContentPage
public Color ColorBC3 { get; set; } = Colors.Transparent;
public Color ColorBC4 { get; set; } = Colors.Transparent;
public Gameboard()
public Gameboard(string caller)
{
InitializeComponent();
BindingContext = game;
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)
{
await PopUpEnd();
@ -235,9 +256,7 @@ public partial class Gameboard : ContentPage
if (answer)
{
await Navigation.PushAsync(new MainPage());
await Navigation.PopToRootAsync();
}
}

@ -8,9 +8,9 @@
<ContentPage.Resources>
<x:Double x:Key="CellWidth">75</x:Double>
<x:Double x:Key="CellHeight">75</x:Double>
<x:Double x:Key="VerticalSpacing">1</x:Double>
<x:Double x:Key="HorizontalSpacing">1</x:Double>
<x:Double x:Key="CellHeight">75</x:Double>
<x:Double x:Key="VerticalSpacing">1</x:Double>
<x:Double x:Key="HorizontalSpacing">1</x:Double>
<toolkit:MultiMathExpressionConverter x:Key="multiMathExpressionConverter" />
</ContentPage.Resources>
<Grid BackgroundColor="#efca85">
@ -28,23 +28,24 @@
<Border WidthRequest="80" HeightRequest="80"
BackgroundColor="Transparent"
Margin="0" >
<Border.GestureRecognizers >
BackgroundColor="Transparent"
Margin="0">
<Border.GestureRecognizers>
<DropGestureRecognizer DragOver="OnDragOverBag"
DropCommand="{Binding OnDropB, Source={x:Reference root}}"
/>
DropCommand="{Binding OnDropB, Source={x:Reference root}}" />
</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>
<Button
<Button
HorizontalOptions="Start"
Grid.Row="0" Grid.Column="1"
Text="Swap"
Clicked="OnButtonSwapClicked"
ToolTipProperties.Text="Click to swap your tiles !"
Style="{StaticResource GameButton}"/>
Style="{StaticResource GameButton}" />
<Button
HorizontalOptions="End"
@ -52,14 +53,14 @@
Text="Skip / End Turn" WidthRequest="200"
Clicked="OnButtonSkipClicked"
ToolTipProperties.Text="Click for skip / end your turn ;)"
Style="{StaticResource GameButton}"/>
<Button
HorizontalOptions="Start"
Style="{StaticResource GameButton}" />
<Button
HorizontalOptions="Start"
Grid.Row="2" Grid.Column="1"
Text="Settings"
ToolTipProperties.Text="Click to check your settings -_-"
Style="{StaticResource GameButton}"/>
Style="{StaticResource GameButton}" />
<Button
HorizontalOptions="End"
@ -67,23 +68,22 @@
Text="Exit" WidthRequest="200"
Clicked="OnButtonExitClicked"
ToolTipProperties.Text="Click here to exit ;)"
Style="{StaticResource GameButton}"/>
Style="{StaticResource GameButton}" />
<CollectionView Grid.Row="0" Grid.Column="1" ItemsSource="{Binding PlayerList[0].Tiles}"
HorizontalOptions="Center"
VerticalOptions="Center" >
VerticalOptions="Center">
<CollectionView.ItemsLayout>
<GridItemsLayout Orientation="Horizontal"/>
<GridItemsLayout Orientation="Horizontal" />
</CollectionView.ItemsLayout>
<CollectionView.ItemTemplate>
<DataTemplate>
<Border WidthRequest="70" HeightRequest="70"
BackgroundColor="{Binding ColorBC1, Source={x:Reference root}}"
Margin="0"
>
BackgroundColor="{Binding ColorBC1, Source={x:Reference root}}"
Margin="0">
<Border.GestureRecognizers>
<DragGestureRecognizer CanDrag="True" DragStarting="OnDragStarting"/>
<DragGestureRecognizer CanDrag="True" DragStarting="OnDragStarting" />
</Border.GestureRecognizers>
<controls:TileView Shape="{Binding GetShape}" Color="{Binding GetColor}"></controls:TileView>
</Border>
@ -93,17 +93,17 @@
<CollectionView Grid.Row="1" Grid.Column="0" ItemsSource="{Binding PlayerList[2].Tiles}"
HorizontalOptions="Center"
VerticalOptions="Center" >
VerticalOptions="Center">
<CollectionView.ItemsLayout>
<GridItemsLayout Orientation="Vertical"/>
<GridItemsLayout Orientation="Vertical" />
</CollectionView.ItemsLayout>
<CollectionView.ItemTemplate>
<DataTemplate>
<Border WidthRequest="70" HeightRequest="70"
BackgroundColor="{Binding ColorBC3, Source={x:Reference root}}"
Margin="0">
BackgroundColor="{Binding ColorBC3, Source={x:Reference root}}"
Margin="0">
<Border.GestureRecognizers>
<DragGestureRecognizer CanDrag="True" DragStarting="OnDragStarting"/>
<DragGestureRecognizer CanDrag="True" DragStarting="OnDragStarting" />
</Border.GestureRecognizers>
<controls:TileView Shape="{Binding GetShape}" Color="{Binding GetColor}"></controls:TileView>
</Border>
@ -113,17 +113,17 @@
<CollectionView Grid.Row="1" Grid.Column="2" ItemsSource="{Binding PlayerList[3].Tiles}"
HorizontalOptions="Center"
VerticalOptions="Center" >
VerticalOptions="Center">
<CollectionView.ItemsLayout>
<GridItemsLayout Orientation="Vertical"/>
<GridItemsLayout Orientation="Vertical" />
</CollectionView.ItemsLayout>
<CollectionView.ItemTemplate>
<DataTemplate>
<Border WidthRequest="70" HeightRequest="70"
BackgroundColor="{Binding ColorBC4, Source={x:Reference root}}"
Margin="0">
BackgroundColor="{Binding ColorBC4, Source={x:Reference root}}"
Margin="0">
<Border.GestureRecognizers>
<DragGestureRecognizer CanDrag="True" DragStarting="OnDragStarting"/>
<DragGestureRecognizer CanDrag="True" DragStarting="OnDragStarting" />
</Border.GestureRecognizers>
<controls:TileView Shape="{Binding GetShape}" Color="{Binding GetColor}"></controls:TileView>
</Border>
@ -133,17 +133,17 @@
<CollectionView Grid.Row="2" Grid.Column="1" ItemsSource="{Binding PlayerList[1].Tiles}"
HorizontalOptions="Center"
VerticalOptions="Start" >
VerticalOptions="Start">
<CollectionView.ItemsLayout>
<GridItemsLayout Orientation="Horizontal"/>
<GridItemsLayout Orientation="Horizontal" />
</CollectionView.ItemsLayout>
<CollectionView.ItemTemplate>
<DataTemplate>
<Border WidthRequest="70" HeightRequest="70"
BackgroundColor="{Binding ColorBC2, Source={x:Reference root}}"
BackgroundColor="{Binding ColorBC2, Source={x:Reference root}}"
Margin="0">
<Border.GestureRecognizers>
<DragGestureRecognizer CanDrag="True" DragStarting="OnDragStarting"/>
<DragGestureRecognizer CanDrag="True" DragStarting="OnDragStarting" />
</Border.GestureRecognizers>
<controls:TileView Shape="{Binding GetShape}" Color="{Binding GetColor}"></controls:TileView>
</Border>
@ -154,56 +154,59 @@
<ScrollView Grid.Row="1" Grid.Column="1" VerticalOptions="FillAndExpand">
<CollectionView ItemsSource="{Binding Board.ReadCells}"
HorizontalOptions="Center"
VerticalOptions="Center" HorizontalScrollBarVisibility="Never" VerticalScrollBarVisibility="Never"
>
VerticalOptions="Center" HorizontalScrollBarVisibility="Never"
VerticalScrollBarVisibility="Never">
<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 Source="{StaticResource CellHeight}" />
<Binding Source="{StaticResource VerticalSpacing}" />
</MultiBinding>
</CollectionView.HeightRequest>
<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 Source="{StaticResource CellWidth}" />
<Binding Source="{StaticResource HorizontalSpacing}" />
</MultiBinding>
</CollectionView.WidthRequest>
<CollectionView.ItemsLayout>
<GridItemsLayout Orientation="Vertical"
Span="{Binding Board.Columns}"
HorizontalItemSpacing="{StaticResource HorizontalSpacing}"
VerticalItemSpacing="{StaticResource VerticalSpacing}"/>
Span="{Binding Board.Columns}"
HorizontalItemSpacing="{StaticResource HorizontalSpacing}"
VerticalItemSpacing="{StaticResource VerticalSpacing}" />
</CollectionView.ItemsLayout>
<CollectionView.ItemTemplate>
<DataTemplate>
<Border WidthRequest="{StaticResource CellWidth}"
HeightRequest="{StaticResource CellHeight}"
HeightRequest="{StaticResource CellHeight}"
BackgroundColor="WhiteSmoke">
<Border.GestureRecognizers >
<Border.GestureRecognizers>
<DropGestureRecognizer DragOver="OnDragOver"
DropCommand="{Binding OnDrop, Source={x:Reference root}}"
DropCommandParameter="{Binding .}"/>
DropCommandParameter="{Binding .}" />
</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>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</ScrollView>
<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>
</ContentPage>
</ContentPage>

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

Loading…
Cancel
Save