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

@ -12,7 +12,11 @@ namespace Qwirkle
{
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();
MainPage = new AppShell();
@ -24,8 +28,16 @@ namespace Qwirkle
Routing.RegisterRoute(nameof(Qwirkle.Pages.Leaderboard), typeof(Qwirkle.Pages.Leaderboard));
ILeaderboardPersistence leaderboardLoad = new LeaderboardPersistenceJson();
try
{
Ld = leaderboardLoad.LoadLeaderboard();
}
catch
{
Ld = new Leaderboard();
}
}
public Game Game { get; set; } = new();

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

@ -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,16 +30,37 @@ 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)
@ -235,9 +256,7 @@ public partial class Gameboard : ContentPage
if (answer)
{
await Navigation.PushAsync(new MainPage());
await Navigation.PopToRootAsync();
}
}

@ -32,10 +32,11 @@
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
@ -82,8 +83,7 @@
<Border WidthRequest="70" HeightRequest="70"
BackgroundColor="{Binding ColorBC1, Source={x:Reference root}}"
Margin="0"
>
Margin="0">
<Border.GestureRecognizers>
<DragGestureRecognizer CanDrag="True" DragStarting="OnDragStarting" />
</Border.GestureRecognizers>
@ -160,12 +160,13 @@
<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}" />
@ -176,7 +177,8 @@
<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}" />
@ -200,7 +202,9 @@
DropCommand="{Binding OnDrop, Source={x:Reference root}}"
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>
@ -210,6 +214,5 @@
<controls:Scoreboard InputTransparent="True" HorizontalOptions="End" Grid.Row="1" Grid.Column="1"></controls:Scoreboard>
</Grid>
</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