c'est bon frere

test_old_branch
Jérémy Mouyon 11 months ago
parent 15f0c4e1ef
commit 09d2d5adb5

@ -396,14 +396,6 @@ namespace QwirkleClassLibrary.Games
return false; return false;
} }
foreach (var t in tilesToSwap)
{
if (!player.RemoveTileToPlayer(t))
{
return false;
}
}
if (!DrawTiles(player)) if (!DrawTiles(player))
{ {
return false; return false;

@ -155,6 +155,7 @@ static void SwapTile(Game game)
else else
{ {
tilesToSwap.Add(game.TileOfPlayerWithPos(no - 1)); tilesToSwap.Add(game.TileOfPlayerWithPos(no - 1));
game.PlayerList[game.GetPlayingPlayerPosition()].RemoveTileToPlayer(game.TileOfPlayerWithPos(no - 1));
} }
Write("Do you want to swap another tile ? (y/n) : "); Write("Do you want to swap another tile ? (y/n) : ");

@ -5,7 +5,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Qwirkle" xmlns:local="clr-namespace:Qwirkle"
xmlns:localPages="clr-namespace:Qwirkle.Pages" xmlns:localPages="clr-namespace:Qwirkle.Pages"
Shell.FlyoutBehavior="Flyout" Shell.FlyoutBehavior="Disabled"
Title="Qwirkle" Title="Qwirkle"
FlyoutBackgroundColor="White"> FlyoutBackgroundColor="White">
@ -27,10 +27,6 @@
Title="Leaderboard" Title="Leaderboard"
ContentTemplate="{DataTemplate localPages:Leaderboard}" ContentTemplate="{DataTemplate localPages:Leaderboard}"
Route="Leaderboard" /> Route="Leaderboard" />
<ShellContent
Title="Scoreboard"
ContentTemplate="{DataTemplate localPages:Scoreboard}"
Route="Scoreboard" />
<ShellContent <ShellContent
Title="Settings" Title="Settings"
ContentTemplate="{DataTemplate localPages:Settings}" ContentTemplate="{DataTemplate localPages:Settings}"

@ -149,7 +149,7 @@ public partial class Gameboard : ContentPage
game.PlaceTileNotified += Game_PlaceTileNotified; game.PlaceTileNotified += Game_PlaceTileNotified;
game.SwapTilesNotified += Game_SwapTilesNotified; game.SwapTilesNotified += Game_SwapTilesNotified;
if(game.CellsUsed.Count == 0 && game.PlayerSwapping==false) if (game.CellsUsed.Count == 0 && !game.PlayerSwapping)
{ {
DisplayAlert("Swap system", "\r\nWelcome to the swap system! To use the system, take the tiles you wish to swap and place them in the bag (you will not see the tiles disappear). Then, click on the skip button. /!\\ Attention, during the swap phase, you cannot play /!\\", "Copy !"); DisplayAlert("Swap system", "\r\nWelcome to the swap system! To use the system, take the tiles you wish to swap and place them in the bag (you will not see the tiles disappear). Then, click on the skip button. /!\\ Attention, during the swap phase, you cannot play /!\\", "Copy !");
game.PlayerSwapping = true; game.PlayerSwapping = true;
@ -168,6 +168,7 @@ public partial class Gameboard : ContentPage
{ {
if (game.PlayerSwapping) if (game.PlayerSwapping)
{ {
game.PlayerList[game.GetPlayingPlayerPosition()].RemoveTileToPlayer(tiledrag);
tilesSwap.Add(tiledrag!); tilesSwap.Add(tiledrag!);
} }
} }

@ -3,7 +3,18 @@
x:Class="Qwirkle.Pages.Gameboard" x:Class="Qwirkle.Pages.Gameboard"
xmlns:controls="clr-namespace:Qwirkle.Views" xmlns:controls="clr-namespace:Qwirkle.Views"
Title="Gameboard" Title="Gameboard"
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
x:Name="root"> x:Name="root">
<ContentPage.Resources>
<ResourceDictionary>
<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>
<toolkit:MultiMathExpressionConverter x:Key="multiMathExpressionConverter" />
</ResourceDictionary>
</ContentPage.Resources>
<Grid> <Grid>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="*" /> <RowDefinition Height="*" />
@ -119,16 +130,40 @@
<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"> VerticalOptions="Center" HorizontalScrollBarVisibility="Never" VerticalScrollBarVisibility="Never">
<CollectionView.HeightRequest>
<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 ">
<Binding Path="Board.Columns" />
<Binding Source="{StaticResource CellWidth}" />
<Binding Source="{StaticResource HorizontalSpacing}" />
</MultiBinding>
</CollectionView.WidthRequest>
<CollectionView.ItemsLayout> <CollectionView.ItemsLayout>
<GridItemsLayout Orientation="Vertical" <GridItemsLayout Orientation="Vertical"
Span="{Binding Board.Columns}"/> Span="{Binding Board.Columns}"
HorizontalItemSpacing="{StaticResource HorizontalSpacing}"
VerticalItemSpacing="{StaticResource VerticalSpacing}"/>
</CollectionView.ItemsLayout> </CollectionView.ItemsLayout>
<CollectionView.ItemTemplate> <CollectionView.ItemTemplate>
<DataTemplate> <DataTemplate>
<Border WidthRequest="80" HeightRequest="80" <Border WidthRequest="{StaticResource CellWidth}"
BackgroundColor="WhiteSmoke" HeightRequest="{StaticResource CellHeight}"
Margin="0" > 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}}"
@ -141,6 +176,8 @@
</CollectionView> </CollectionView>
</ScrollView> </ScrollView>
<controls:Scoreboard HorizontalOptions="End" Grid.Row="1" Grid.Column="1" ></controls:Scoreboard>
</Grid> </Grid>

@ -1,50 +0,0 @@
<?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.Pages.Scoreboard"
xmlns:controls="clr-namespace:Qwirkle.Views"
Title="Scoreboard">
<ScrollView>
<VerticalStackLayout Spacing="25" Padding="5, 5, 5, 10">
<Grid Style="{StaticResource GridMain}">
<controls:GoBack></controls:GoBack>
<Label Text="Scoreboard"
Style="{StaticResource Title}"
/>
</Grid>
<Border Style="{StaticResource TabBorder}">
<Border.Shadow>
<Shadow/>
</Border.Shadow>
<Border.StrokeShape>
<RoundRectangle CornerRadius="3"/>
</Border.StrokeShape>
<VerticalStackLayout>
<controls:ScoreboardLine></controls:ScoreboardLine>
<Rectangle/>
<controls:ScoreboardLine></controls:ScoreboardLine>
<Rectangle/>
<controls:ScoreboardLine></controls:ScoreboardLine>
<Rectangle/>
<controls:ScoreboardLine></controls:ScoreboardLine>
<Rectangle/>
<controls:ScoreboardLine></controls:ScoreboardLine>
<Rectangle/>
</VerticalStackLayout>
</Border>
</VerticalStackLayout>
</ScrollView>
</ContentPage>

@ -1,9 +0,0 @@
namespace Qwirkle.Pages;
public partial class Scoreboard : ContentPage
{
public Scoreboard()
{
InitializeComponent();
}
}

@ -87,15 +87,15 @@
<Compile Update="Pages\SetPlayers.xaml.cs"> <Compile Update="Pages\SetPlayers.xaml.cs">
<DependentUpon>SetPlayers.xaml</DependentUpon> <DependentUpon>SetPlayers.xaml</DependentUpon>
</Compile> </Compile>
<Compile Update="Pages\Scoreboard.xaml.cs">
<DependentUpon>Scoreboard.xaml</DependentUpon>
</Compile>
<Compile Update="Pages\Settings.xaml.cs"> <Compile Update="Pages\Settings.xaml.cs">
<DependentUpon>Settings.xaml</DependentUpon> <DependentUpon>Settings.xaml</DependentUpon>
</Compile> </Compile>
<Compile Update="Views\GoBack.xaml.cs"> <Compile Update="Views\GoBack.xaml.cs">
<DependentUpon>GoBack.xaml</DependentUpon> <DependentUpon>GoBack.xaml</DependentUpon>
</Compile> </Compile>
<Compile Update="Views\Scoreboard.xaml.cs">
<DependentUpon>Scoreboard.xaml</DependentUpon>
</Compile>
<Compile Update="Views\ScoreboardLine.xaml.cs"> <Compile Update="Views\ScoreboardLine.xaml.cs">
<DependentUpon>ScoreboardLine.xaml</DependentUpon> <DependentUpon>ScoreboardLine.xaml</DependentUpon>
</Compile> </Compile>
@ -117,9 +117,6 @@
<MauiXaml Update="Pages\SetPlayers.xaml"> <MauiXaml Update="Pages\SetPlayers.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</MauiXaml> </MauiXaml>
<MauiXaml Update="Pages\Scoreboard.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="Pages\Settings.xaml"> <MauiXaml Update="Pages\Settings.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</MauiXaml> </MauiXaml>
@ -132,6 +129,9 @@
<MauiXaml Update="Views\GoBack.xaml"> <MauiXaml Update="Views\GoBack.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</MauiXaml> </MauiXaml>
<MauiXaml Update="Views\Scoreboard.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="Views\ScoreboardLine.xaml"> <MauiXaml Update="Views\ScoreboardLine.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</MauiXaml> </MauiXaml>

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Qwirkle.Views.Scoreboard"
xmlns:controls="clr-namespace:Qwirkle.Views"
x:Name="root">
<VerticalStackLayout MaximumWidthRequest="200" Background="Transparent">
<CollectionView ItemsSource="{Binding NamesPlayers}">
<CollectionView.ItemsLayout>
<GridItemsLayout Orientation="Vertical"/>
</CollectionView.ItemsLayout>
<CollectionView.ItemTemplate>
<DataTemplate>
<controls:ScoreboardLine Nameplayer="{Binding NameTag}"></controls:ScoreboardLine>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</VerticalStackLayout>
</ContentView>

@ -0,0 +1,57 @@
using QwirkleClassLibrary.Players;
using System.Collections.ObjectModel;
using System.ComponentModel;
namespace Qwirkle.Views;
public partial class Scoreboard : ContentView, INotifyPropertyChanged
{
private IOrderedEnumerable<KeyValuePair<Player, int>> scoreboard;
private Dictionary<Player, int> currentScoreBoard;
private List<Player> namesPlayers;
public List<Player> NamesPlayers
{
get => namesPlayers;
set
{
if (namesPlayers != value)
{
namesPlayers = value;
OnPropertyChanged(nameof(NamesPlayers));
}
}
}
public Scoreboard()
{
InitializeComponent();
BindingContext = this;
scoreboard = ((App)Application.Current!).Game.ScoreBoard.OrderByDescending(x => x.Value).ThenBy(x => x.Key.NameTag);
currentScoreBoard = scoreboard.ToDictionary<Player, int>();
NamesPlayers = currentScoreBoard.Keys.ToList();
((App)Application.Current!).Game.Board.PropertyChanged += Board_PropertyChanged;
}
private void Board_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
{
scoreboard = ((App)Application.Current!).Game.ScoreBoard.OrderByDescending(x => x.Value).ThenBy(x => x.Key.NameTag);
currentScoreBoard = scoreboard.ToDictionary<Player, int>();
NamesPlayers = currentScoreBoard.Keys.ToList();
}
public event PropertyChangedEventHandler? PropertyChanged;
protected void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}

@ -2,13 +2,15 @@
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui" <ContentView 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.Views.ScoreboardLine"> x:Class="Qwirkle.Views.ScoreboardLine"
x:Name="root">
<StackLayout>
<Grid ColumnDefinitions="4*, auto, 2*" <Grid ColumnDefinitions="4*, auto, 2*"
RowDefinitions="50"> RowDefinitions="50">
<Label <Label
Grid.Column="0" Grid.Column="0"
Text="{Binding playerName}" Text="{Binding Nameplayer, Source={x:Reference root}}"
Style="{StaticResource ContentTab}"/> Style="{StaticResource ContentTab}"/>
<Rectangle <Rectangle
@ -17,8 +19,10 @@
<Label <Label
Grid.Column="2" Grid.Column="2"
Text="{Binding nbPoints}" Text="0"
Style="{StaticResource ContentTab}"/> Style="{StaticResource ContentTab}"/>
</Grid> </Grid>
<Rectangle/>
</StackLayout>
</ContentView> </ContentView>

@ -11,22 +11,27 @@ namespace Qwirkle.Views;
public partial class ScoreboardLine : ContentView public partial class ScoreboardLine : ContentView
{ {
public ReadOnlyDictionary<Player, int> scoreboard = ((App)App.Current!).Game.ScoreBoard;
List<string> nameTags = scoreboard.Keys.ToList(); public ScoreboardLine()
{
List<int> nbPoints = scoreboard.Values.ToList(); InitializeComponent();
BindingContext = this;
Dictionary<Player, int> modifiableDictionary = new Dictionary<Player, int>(scoreboard); }
public static readonly BindableProperty NameplayerProperty =
BindableProperty.Create(nameof(Nameplayer), typeof(string), typeof(ScoreboardLine), default(string), propertyChanged: OnPlayerChanged);
public static readonly BindableProperty ScoreboardLineProperty = BindableProperty.Create("ScoreBLine", typeof(ScoreboardLine), typeof(object)); public string Nameplayer
{
get => (string)GetValue(NameplayerProperty);
set => SetValue(NameplayerProperty, value);
}
public ScoreboardLine() private static void OnPlayerChanged(BindableObject bindable, object oldValue, object newValue)
{ {
InitializeComponent(); var bin = (ScoreboardLine)bindable;
BindingContext = scoreboard; bin.OnPropertyChanged(nameof(Nameplayer));
} }

@ -15,8 +15,6 @@ namespace Qwirkle.Views;
public partial class TileView : ContentView public partial class TileView : ContentView
{ {
public TileView() public TileView()
{ {
InitializeComponent(); InitializeComponent();
@ -53,11 +51,5 @@ public partial class TileView : ContentView
set => SetValue(ShapeProperty, value); set => SetValue(ShapeProperty, value);
} }
public event EventHandler InfoClicked;
void OnInfoClicked(object sender, EventArgs args)
{
InfoClicked?.Invoke(this, args);
}
} }
Loading…
Cancel
Save