From 028de279096f992d3ebf633ccc2a37bd2244eaa9 Mon Sep 17 00:00:00 2001 From: "jeremy.mouyon" Date: Wed, 5 Jun 2024 16:25:55 +0200 Subject: [PATCH] pls loard --- Qwirkle/QwirkleClassLibrary/Games/Game.cs | 9 +---- Qwirkle/QwirkleViews/ConverterColor.cs | 38 +++++++++---------- Qwirkle/QwirkleViews/Pages/GameBoard.xaml.cs | 4 +- .../QwirkleViews/Views/ButtonShadow.xaml.cs | 2 +- Qwirkle/QwirkleViews/Views/Scoreboard.xaml.cs | 15 ++------ Qwirkle/TestBase/TestBoard.cs | 15 +++++--- 6 files changed, 37 insertions(+), 46 deletions(-) diff --git a/Qwirkle/QwirkleClassLibrary/Games/Game.cs b/Qwirkle/QwirkleClassLibrary/Games/Game.cs index 90549e9..b3f9751 100644 --- a/Qwirkle/QwirkleClassLibrary/Games/Game.cs +++ b/Qwirkle/QwirkleClassLibrary/Games/Game.cs @@ -37,7 +37,7 @@ namespace QwirkleClassLibrary.Games public ReadOnlyDictionary ScoreBoard => scoreBoard.AsReadOnly(); - private ObservableCollection> observableScoreBoard = new ObservableCollection>(); + private readonly ObservableCollection> observableScoreBoard = []; public ReadOnlyObservableCollection> ObservableScoreBoard => new ReadOnlyObservableCollection>(observableScoreBoard); @@ -347,7 +347,6 @@ namespace QwirkleClassLibrary.Games if (!IsMoveCorrect(tile, x, y, board!)) return false; if (board!.AddTileInCell(x, y, tile)) { - OnPlaceTile(new PlaceTileNotifiedEventArgs(tile, "was correctly placed !")); AddCellUsed(board.GetCell(x, y)); return player.RemoveTileToPlayer(tile); } @@ -812,14 +811,10 @@ namespace QwirkleClassLibrary.Games public void SetScoreBoard(string name, int score) { - if (scoreBoard.ContainsKey(name)) + if (!scoreBoard.TryAdd(name, score)) { scoreBoard[name] = score; } - else - { - scoreBoard.Add(name, score); - } observableScoreBoard.Clear(); foreach (var item in scoreBoard) diff --git a/Qwirkle/QwirkleViews/ConverterColor.cs b/Qwirkle/QwirkleViews/ConverterColor.cs index 1887107..ff8ebe7 100644 --- a/Qwirkle/QwirkleViews/ConverterColor.cs +++ b/Qwirkle/QwirkleViews/ConverterColor.cs @@ -5,11 +5,11 @@ namespace Qwirkle.Converters { public class Int2ColorConverter : IValueConverter { - public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) { if (value is not string) return Colors.Transparent; - string colorstring = (string)value; + string? colorstring = (string)value; if (string.IsNullOrWhiteSpace(colorstring)) return Colors.Transparent; @@ -33,17 +33,17 @@ namespace Qwirkle.Converters public class RoundToVisibilityConverter : IValueConverter { - public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) { if (value is not string) return false; - string sh = (string)value; + string? sh = (string)value; return sh == "Round"; } - public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) { throw new NotSupportedException(); } @@ -51,17 +51,17 @@ namespace Qwirkle.Converters public class RhombusToVisibilityConverter : IValueConverter { - public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) { if (value is not string) return false; - string sh = (string)value; + string? sh = (string)value; return sh == "Rhombus"; } - public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) { throw new NotSupportedException(); } @@ -69,17 +69,17 @@ namespace Qwirkle.Converters public class SquareToVisibilityConverter : IValueConverter { - public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) { if (value is not string) return false; - string sh = (string)value; + string? sh = (string)value; return sh == "Square"; } - public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) { throw new NotSupportedException(); } @@ -87,17 +87,17 @@ namespace Qwirkle.Converters public class ClubToVisibilityConverter : IValueConverter { - public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) { if (value is not string) return false; - string sh = (string)value; + string? sh = (string)value; return sh == "Club"; } - public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) { throw new NotSupportedException(); } @@ -105,17 +105,17 @@ namespace Qwirkle.Converters public class ShurikenToVisibilityConverter : IValueConverter { - public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) { if (value is not string) return false; - string sh = (string)value; + string? sh = (string)value; return sh == "Shuriken"; } - public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) { throw new NotSupportedException(); } @@ -123,12 +123,12 @@ namespace Qwirkle.Converters public class StarToVisibilityConverter : IValueConverter { - public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) { if (value is not string) return false; - string sh = (string)value; + string? sh = (string)value; return sh == "Star"; } diff --git a/Qwirkle/QwirkleViews/Pages/GameBoard.xaml.cs b/Qwirkle/QwirkleViews/Pages/GameBoard.xaml.cs index b200327..3df7d1e 100644 --- a/Qwirkle/QwirkleViews/Pages/GameBoard.xaml.cs +++ b/Qwirkle/QwirkleViews/Pages/GameBoard.xaml.cs @@ -37,7 +37,7 @@ public partial class Gameboard : ContentPage } private void OnDragStarting(object sender, DragStartingEventArgs e) { - var tile = (sender as Element).BindingContext as Tile; + var tile = ((Element)sender).BindingContext as Tile; e.Data.Text = tile?.ToString(); tiledrag = tile; } @@ -176,7 +176,7 @@ public partial class Gameboard : ContentPage { if (game.PlayerSwapping) { - game.PlayerList[game.GetPlayingPlayerPosition()].RemoveTileToPlayer(tiledrag); + game.PlayerList[game.GetPlayingPlayerPosition()].RemoveTileToPlayer(tiledrag!); tilesSwap.Add(tiledrag!); } } diff --git a/Qwirkle/QwirkleViews/Views/ButtonShadow.xaml.cs b/Qwirkle/QwirkleViews/Views/ButtonShadow.xaml.cs index 095ae3f..9b5e719 100644 --- a/Qwirkle/QwirkleViews/Views/ButtonShadow.xaml.cs +++ b/Qwirkle/QwirkleViews/Views/ButtonShadow.xaml.cs @@ -18,7 +18,7 @@ public partial class ButtonShadow : ContentView set => SetValue(TextProperty, value); } - public event EventHandler InfoClicked; + public event EventHandler? InfoClicked; void OnInfoClicked(object sender, EventArgs args) { diff --git a/Qwirkle/QwirkleViews/Views/Scoreboard.xaml.cs b/Qwirkle/QwirkleViews/Views/Scoreboard.xaml.cs index 1bbe5de..130bb05 100644 --- a/Qwirkle/QwirkleViews/Views/Scoreboard.xaml.cs +++ b/Qwirkle/QwirkleViews/Views/Scoreboard.xaml.cs @@ -7,12 +7,12 @@ using System.Linq; namespace Qwirkle.Views { - public partial class Scoreboard : ContentView, INotifyPropertyChanged + public partial class Scoreboard : ContentView { private Game game = ((App)Application.Current!).Game; - private ObservableCollection> scoreboardList; - public ObservableCollection> ScoreboardList + private ObservableCollection>? scoreboardList; + public ObservableCollection>? ScoreboardList { get => scoreboardList; set @@ -41,16 +41,9 @@ namespace Qwirkle.Views ScoreboardList = new ObservableCollection>(scoreboard); } - private void OnScoreChanged(object sender, EventArgs e) + private void OnScoreChanged(object? sender, EventArgs e) { UpdateScoreboard(); } - - public event PropertyChangedEventHandler PropertyChanged; - - protected void OnPropertyChanged(string propertyName) - { - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); - } } } diff --git a/Qwirkle/TestBase/TestBoard.cs b/Qwirkle/TestBase/TestBoard.cs index 98088e5..c2408a7 100644 --- a/Qwirkle/TestBase/TestBoard.cs +++ b/Qwirkle/TestBase/TestBoard.cs @@ -6,21 +6,23 @@ namespace TestBase; public class TestBoard { - public static TheoryData DataBoard() + public static TheoryData DataBoard() { - var data = new TheoryData + var data = new TheoryData { { true, 1, 2, - new Tile(Shape.Round, Color.Red) + Shape.Round, + Color.Red }, { false, -5, 9999, - new Tile(Shape.Round, Color.Red) + Shape.Round, + Color.Red } }; return data; @@ -28,9 +30,10 @@ public class TestBoard [Theory] [MemberData(nameof(DataBoard))] - public void Test_BoardAddSolo(bool except, int x, int y, Tile t) + public void Test_BoardAddSolo(bool except, int x, int y, Shape shape, Color color) { - + + Tile t = new Tile(shape, color); Board b = new Board(12, 12); if (!except)