Jérémy Mouyon 11 months ago
commit 285243756f

@ -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);

@ -12,7 +12,11 @@ namespace Qwirkle
{ {
public App() public App()
{ {
Directory.SetCurrentDirectory(Path.Combine(Directory.GetCurrentDirectory(), "..\\..\\..\\Files")); string appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
string targetPath = Path.Combine(appDataPath, "Programs", "Files");
Directory.CreateDirectory(targetPath);
Directory.SetCurrentDirectory(targetPath);
InitializeComponent(); InitializeComponent();
MainPage = new AppShell(); MainPage = new AppShell();
@ -24,8 +28,16 @@ namespace Qwirkle
Routing.RegisterRoute(nameof(Qwirkle.Pages.Leaderboard), typeof(Qwirkle.Pages.Leaderboard)); Routing.RegisterRoute(nameof(Qwirkle.Pages.Leaderboard), typeof(Qwirkle.Pages.Leaderboard));
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,34 +12,32 @@
<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" />
<controls:ButtonShadow Text="Rules" <controls:ButtonShadow Text="Rules"
InfoClicked="OnRulesClicked"/> InfoClicked="OnRulesClicked" />
<controls:ButtonShadow Text="Settings" <controls:ButtonShadow Text="Settings"
InfoClicked="OnSettingsClicked"/> InfoClicked="OnSettingsClicked" />
<controls:ButtonShadow Text="Credits" <controls:ButtonShadow Text="Credits"
InfoClicked="OnCreditsClicked"/> InfoClicked="OnCreditsClicked" />
</VerticalStackLayout> </VerticalStackLayout>

@ -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();
} }
} }

@ -29,13 +29,14 @@
<Border WidthRequest="80" HeightRequest="80" <Border WidthRequest="80" HeightRequest="80"
BackgroundColor="Transparent" BackgroundColor="Transparent"
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
@ -44,7 +45,7 @@
Text="Swap" Text="Swap"
Clicked="OnButtonSwapClicked" Clicked="OnButtonSwapClicked"
ToolTipProperties.Text="Click to swap your tiles !" ToolTipProperties.Text="Click to swap your tiles !"
Style="{StaticResource GameButton}"/> Style="{StaticResource GameButton}" />
<Button <Button
HorizontalOptions="End" HorizontalOptions="End"
@ -52,14 +53,14 @@
Text="Skip / End Turn" WidthRequest="200" Text="Skip / End Turn" WidthRequest="200"
Clicked="OnButtonSkipClicked" Clicked="OnButtonSkipClicked"
ToolTipProperties.Text="Click for skip / end your turn ;)" ToolTipProperties.Text="Click for skip / end your turn ;)"
Style="{StaticResource GameButton}"/> Style="{StaticResource GameButton}" />
<Button <Button
HorizontalOptions="Start" HorizontalOptions="Start"
Grid.Row="2" Grid.Column="1" Grid.Row="2" Grid.Column="1"
Text="Settings" Text="Settings"
ToolTipProperties.Text="Click to check your settings -_-" ToolTipProperties.Text="Click to check your settings -_-"
Style="{StaticResource GameButton}"/> Style="{StaticResource GameButton}" />
<Button <Button
HorizontalOptions="End" HorizontalOptions="End"
@ -67,14 +68,14 @@
Text="Exit" WidthRequest="200" Text="Exit" WidthRequest="200"
Clicked="OnButtonExitClicked" Clicked="OnButtonExitClicked"
ToolTipProperties.Text="Click here to exit ;)" ToolTipProperties.Text="Click here to exit ;)"
Style="{StaticResource GameButton}"/> Style="{StaticResource GameButton}" />
<Label HorizontalOptions="Center" Grid.Row="0" Grid.Column="1" Text="{Binding PlayerList[0].NameTag}"></Label> <Label HorizontalOptions="Center" Grid.Row="0" Grid.Column="1" Text="{Binding PlayerList[0].NameTag}"></Label>
<CollectionView Grid.Row="0" Grid.Column="1" ItemsSource="{Binding PlayerList[0].Tiles}" <CollectionView Grid.Row="0" Grid.Column="1" ItemsSource="{Binding PlayerList[0].Tiles}"
HorizontalOptions="Center" HorizontalOptions="Center"
VerticalOptions="Center" > VerticalOptions="Center">
<CollectionView.ItemsLayout> <CollectionView.ItemsLayout>
<GridItemsLayout Orientation="Horizontal"/> <GridItemsLayout Orientation="Horizontal" />
</CollectionView.ItemsLayout> </CollectionView.ItemsLayout>
<CollectionView.ItemTemplate> <CollectionView.ItemTemplate>
@ -82,10 +83,9 @@
<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>
<controls:TileView Shape="{Binding GetShape}" Color="{Binding GetColor}"></controls:TileView> <controls:TileView Shape="{Binding GetShape}" Color="{Binding GetColor}"></controls:TileView>
</Border> </Border>
@ -97,9 +97,9 @@
<Label HorizontalOptions="Center" Grid.Row="1" Grid.Column="0" Text="{Binding PlayerList[2].NameTag}"></Label> <Label HorizontalOptions="Center" Grid.Row="1" Grid.Column="0" Text="{Binding PlayerList[2].NameTag}"></Label>
<CollectionView Grid.Row="1" Grid.Column="0" ItemsSource="{Binding PlayerList[2].Tiles}" <CollectionView Grid.Row="1" Grid.Column="0" ItemsSource="{Binding PlayerList[2].Tiles}"
HorizontalOptions="Center" HorizontalOptions="Center"
VerticalOptions="Center" > VerticalOptions="Center">
<CollectionView.ItemsLayout> <CollectionView.ItemsLayout>
<GridItemsLayout Orientation="Vertical"/> <GridItemsLayout Orientation="Vertical" />
</CollectionView.ItemsLayout> </CollectionView.ItemsLayout>
<CollectionView.ItemTemplate> <CollectionView.ItemTemplate>
<DataTemplate> <DataTemplate>
@ -107,7 +107,7 @@
BackgroundColor="{Binding ColorBC3, Source={x:Reference root}}" BackgroundColor="{Binding ColorBC3, 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>
<controls:TileView Shape="{Binding GetShape}" Color="{Binding GetColor}"></controls:TileView> <controls:TileView Shape="{Binding GetShape}" Color="{Binding GetColor}"></controls:TileView>
</Border> </Border>
@ -118,9 +118,9 @@
<Label HorizontalOptions="Center" Grid.Row="1" Grid.Column="2" Text="{Binding PlayerList[3].NameTag}"></Label> <Label HorizontalOptions="Center" Grid.Row="1" Grid.Column="2" Text="{Binding PlayerList[3].NameTag}"></Label>
<CollectionView Grid.Row="1" Grid.Column="2" ItemsSource="{Binding PlayerList[3].Tiles}" <CollectionView Grid.Row="1" Grid.Column="2" ItemsSource="{Binding PlayerList[3].Tiles}"
HorizontalOptions="Center" HorizontalOptions="Center"
VerticalOptions="Center" > VerticalOptions="Center">
<CollectionView.ItemsLayout> <CollectionView.ItemsLayout>
<GridItemsLayout Orientation="Vertical"/> <GridItemsLayout Orientation="Vertical" />
</CollectionView.ItemsLayout> </CollectionView.ItemsLayout>
<CollectionView.ItemTemplate> <CollectionView.ItemTemplate>
<DataTemplate> <DataTemplate>
@ -128,7 +128,7 @@
BackgroundColor="{Binding ColorBC4, Source={x:Reference root}}" BackgroundColor="{Binding ColorBC4, 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>
<controls:TileView Shape="{Binding GetShape}" Color="{Binding GetColor}"></controls:TileView> <controls:TileView Shape="{Binding GetShape}" Color="{Binding GetColor}"></controls:TileView>
</Border> </Border>
@ -139,9 +139,9 @@
<Label HorizontalOptions="Center" VerticalOptions="End" Grid.Row="2" Grid.Column="1" Text="{Binding PlayerList[1].NameTag}"></Label> <Label HorizontalOptions="Center" VerticalOptions="End" Grid.Row="2" Grid.Column="1" Text="{Binding PlayerList[1].NameTag}"></Label>
<CollectionView Grid.Row="2" Grid.Column="1" ItemsSource="{Binding PlayerList[1].Tiles}" <CollectionView Grid.Row="2" Grid.Column="1" ItemsSource="{Binding PlayerList[1].Tiles}"
HorizontalOptions="Center" HorizontalOptions="Center"
VerticalOptions="Start" > VerticalOptions="Start">
<CollectionView.ItemsLayout> <CollectionView.ItemsLayout>
<GridItemsLayout Orientation="Horizontal"/> <GridItemsLayout Orientation="Horizontal" />
</CollectionView.ItemsLayout> </CollectionView.ItemsLayout>
<CollectionView.ItemTemplate> <CollectionView.ItemTemplate>
<DataTemplate> <DataTemplate>
@ -149,7 +149,7 @@
BackgroundColor="{Binding ColorBC2, Source={x:Reference root}}" BackgroundColor="{Binding ColorBC2, 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>
<controls:TileView Shape="{Binding GetShape}" Color="{Binding GetColor}"></controls:TileView> <controls:TileView Shape="{Binding GetShape}" Color="{Binding GetColor}"></controls:TileView>
</Border> </Border>
@ -160,12 +160,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}" />
@ -176,7 +177,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}" />
@ -188,27 +190,28 @@
<GridItemsLayout Orientation="Vertical" <GridItemsLayout Orientation="Vertical"
Span="{Binding Board.Columns}" Span="{Binding Board.Columns}"
HorizontalItemSpacing="{StaticResource HorizontalSpacing}" HorizontalItemSpacing="{StaticResource HorizontalSpacing}"
VerticalItemSpacing="{StaticResource VerticalSpacing}"/> VerticalItemSpacing="{StaticResource VerticalSpacing}" />
</CollectionView.ItemsLayout> </CollectionView.ItemsLayout>
<CollectionView.ItemTemplate> <CollectionView.ItemTemplate>
<DataTemplate> <DataTemplate>
<Border WidthRequest="{StaticResource CellWidth}" <Border WidthRequest="{StaticResource CellWidth}"
HeightRequest="{StaticResource CellHeight}" HeightRequest="{StaticResource CellHeight}"
BackgroundColor="WhiteSmoke"> BackgroundColor="WhiteSmoke">
<Border.GestureRecognizers > <Border.GestureRecognizers>
<DropGestureRecognizer DragOver="OnDragOver" <DropGestureRecognizer DragOver="OnDragOver"
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>
</CollectionView> </CollectionView>
</ScrollView> </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> </Grid>

@ -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