From 09d2d5adb5e98fe32696e4d3c16671c2fced08c7 Mon Sep 17 00:00:00 2001 From: "jeremy.mouyon" Date: Mon, 3 Jun 2024 19:30:49 +0200 Subject: [PATCH] c'est bon frere --- Qwirkle/QwirkleClassLibrary/Games/Game.cs | 8 --- Qwirkle/QwirkleConsoleApp/Program.cs | 1 + Qwirkle/QwirkleViews/AppShell.xaml | 6 +- Qwirkle/QwirkleViews/Pages/GameBoard.xaml.cs | 3 +- Qwirkle/QwirkleViews/Pages/Gameboard.xaml | 49 ++++++++++++++-- Qwirkle/QwirkleViews/Pages/Scoreboard.xaml | 50 ---------------- Qwirkle/QwirkleViews/Pages/Scoreboard.xaml.cs | 9 --- Qwirkle/QwirkleViews/QwirkleViews.csproj | 12 ++-- Qwirkle/QwirkleViews/Views/Scoreboard.xaml | 24 ++++++++ Qwirkle/QwirkleViews/Views/Scoreboard.xaml.cs | 57 +++++++++++++++++++ .../QwirkleViews/Views/ScoreboardLine.xaml | 12 ++-- .../QwirkleViews/Views/ScoreboardLine.xaml.cs | 25 ++++---- Qwirkle/QwirkleViews/Views/TileView.xaml.cs | 8 --- 13 files changed, 157 insertions(+), 107 deletions(-) delete mode 100644 Qwirkle/QwirkleViews/Pages/Scoreboard.xaml delete mode 100644 Qwirkle/QwirkleViews/Pages/Scoreboard.xaml.cs create mode 100644 Qwirkle/QwirkleViews/Views/Scoreboard.xaml create mode 100644 Qwirkle/QwirkleViews/Views/Scoreboard.xaml.cs diff --git a/Qwirkle/QwirkleClassLibrary/Games/Game.cs b/Qwirkle/QwirkleClassLibrary/Games/Game.cs index ad12627..464bee2 100644 --- a/Qwirkle/QwirkleClassLibrary/Games/Game.cs +++ b/Qwirkle/QwirkleClassLibrary/Games/Game.cs @@ -396,14 +396,6 @@ namespace QwirkleClassLibrary.Games return false; } - foreach (var t in tilesToSwap) - { - if (!player.RemoveTileToPlayer(t)) - { - return false; - } - } - if (!DrawTiles(player)) { return false; diff --git a/Qwirkle/QwirkleConsoleApp/Program.cs b/Qwirkle/QwirkleConsoleApp/Program.cs index a6224bb..a55e702 100644 --- a/Qwirkle/QwirkleConsoleApp/Program.cs +++ b/Qwirkle/QwirkleConsoleApp/Program.cs @@ -155,6 +155,7 @@ static void SwapTile(Game game) else { 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) : "); diff --git a/Qwirkle/QwirkleViews/AppShell.xaml b/Qwirkle/QwirkleViews/AppShell.xaml index 714eaaf..c75f2a2 100644 --- a/Qwirkle/QwirkleViews/AppShell.xaml +++ b/Qwirkle/QwirkleViews/AppShell.xaml @@ -5,7 +5,7 @@ xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:Qwirkle" xmlns:localPages="clr-namespace:Qwirkle.Pages" - Shell.FlyoutBehavior="Flyout" + Shell.FlyoutBehavior="Disabled" Title="Qwirkle" FlyoutBackgroundColor="White"> @@ -27,10 +27,6 @@ Title="Leaderboard" ContentTemplate="{DataTemplate localPages:Leaderboard}" Route="Leaderboard" /> - + + + + 75 + 75 + 1 + 1 + + + @@ -119,16 +130,40 @@ + VerticalOptions="Center" HorizontalScrollBarVisibility="Never" VerticalScrollBarVisibility="Never"> + + + + + + + + + + + + + + + + + + + + + + + Span="{Binding Board.Columns}" + HorizontalItemSpacing="{StaticResource HorizontalSpacing}" + VerticalItemSpacing="{StaticResource VerticalSpacing}"/> - + + + - + diff --git a/Qwirkle/QwirkleViews/Pages/Scoreboard.xaml b/Qwirkle/QwirkleViews/Pages/Scoreboard.xaml deleted file mode 100644 index 6651f91..0000000 --- a/Qwirkle/QwirkleViews/Pages/Scoreboard.xaml +++ /dev/null @@ -1,50 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Qwirkle/QwirkleViews/Pages/Scoreboard.xaml.cs b/Qwirkle/QwirkleViews/Pages/Scoreboard.xaml.cs deleted file mode 100644 index 7846686..0000000 --- a/Qwirkle/QwirkleViews/Pages/Scoreboard.xaml.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Qwirkle.Pages; - -public partial class Scoreboard : ContentPage -{ - public Scoreboard() - { - InitializeComponent(); - } -} \ No newline at end of file diff --git a/Qwirkle/QwirkleViews/QwirkleViews.csproj b/Qwirkle/QwirkleViews/QwirkleViews.csproj index 54ad304..6d75889 100644 --- a/Qwirkle/QwirkleViews/QwirkleViews.csproj +++ b/Qwirkle/QwirkleViews/QwirkleViews.csproj @@ -87,15 +87,15 @@ SetPlayers.xaml - - Scoreboard.xaml - Settings.xaml GoBack.xaml + + Scoreboard.xaml + ScoreboardLine.xaml @@ -117,9 +117,6 @@ MSBuild:Compile - - MSBuild:Compile - MSBuild:Compile @@ -132,6 +129,9 @@ MSBuild:Compile + + MSBuild:Compile + MSBuild:Compile diff --git a/Qwirkle/QwirkleViews/Views/Scoreboard.xaml b/Qwirkle/QwirkleViews/Views/Scoreboard.xaml new file mode 100644 index 0000000..1982d53 --- /dev/null +++ b/Qwirkle/QwirkleViews/Views/Scoreboard.xaml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/Qwirkle/QwirkleViews/Views/Scoreboard.xaml.cs b/Qwirkle/QwirkleViews/Views/Scoreboard.xaml.cs new file mode 100644 index 0000000..7aa9b84 --- /dev/null +++ b/Qwirkle/QwirkleViews/Views/Scoreboard.xaml.cs @@ -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> scoreboard; + private Dictionary currentScoreBoard; + + private List namesPlayers; + public List 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(); + + 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(); + + NamesPlayers = currentScoreBoard.Keys.ToList(); + + } + + public event PropertyChangedEventHandler? PropertyChanged; + + protected void OnPropertyChanged(string propertyName) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + + + +} \ No newline at end of file diff --git a/Qwirkle/QwirkleViews/Views/ScoreboardLine.xaml b/Qwirkle/QwirkleViews/Views/ScoreboardLine.xaml index 9c743bb..f67d9ec 100644 --- a/Qwirkle/QwirkleViews/Views/ScoreboardLine.xaml +++ b/Qwirkle/QwirkleViews/Views/ScoreboardLine.xaml @@ -2,13 +2,15 @@ - + + + + \ No newline at end of file diff --git a/Qwirkle/QwirkleViews/Views/ScoreboardLine.xaml.cs b/Qwirkle/QwirkleViews/Views/ScoreboardLine.xaml.cs index cae2e7a..0313198 100644 --- a/Qwirkle/QwirkleViews/Views/ScoreboardLine.xaml.cs +++ b/Qwirkle/QwirkleViews/Views/ScoreboardLine.xaml.cs @@ -11,22 +11,27 @@ namespace Qwirkle.Views; public partial class ScoreboardLine : ContentView { - public ReadOnlyDictionary scoreboard = ((App)App.Current!).Game.ScoreBoard; - List nameTags = scoreboard.Keys.ToList(); - - List nbPoints = scoreboard.Values.ToList(); - - Dictionary modifiableDictionary = new Dictionary(scoreboard); + public ScoreboardLine() + { + InitializeComponent(); + BindingContext = this; + } + 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(); - BindingContext = scoreboard; + var bin = (ScoreboardLine)bindable; + bin.OnPropertyChanged(nameof(Nameplayer)); } diff --git a/Qwirkle/QwirkleViews/Views/TileView.xaml.cs b/Qwirkle/QwirkleViews/Views/TileView.xaml.cs index 742beac..beadd41 100644 --- a/Qwirkle/QwirkleViews/Views/TileView.xaml.cs +++ b/Qwirkle/QwirkleViews/Views/TileView.xaml.cs @@ -15,8 +15,6 @@ namespace Qwirkle.Views; public partial class TileView : ContentView { - - public TileView() { InitializeComponent(); @@ -53,11 +51,5 @@ public partial class TileView : ContentView set => SetValue(ShapeProperty, value); } - public event EventHandler InfoClicked; - - void OnInfoClicked(object sender, EventArgs args) - { - InfoClicked?.Invoke(this, args); - } } \ No newline at end of file