fix end game / pop-up / start leaderboard edit
continuous-integration/drone/push Build is failing Details

old_branch_before_remy
Jérémy Mouyon 11 months ago
parent d8d106ced0
commit 1bd9bd0a53

@ -34,13 +34,11 @@ namespace QwirkleClassLibrary.Games
[DataMember] [DataMember]
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();
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 ReadOnlyObservableCollection<KeyValuePair<string, int>>(observableScoreBoard); new(observableScoreBoard);
[DataMember] [DataMember]
private readonly List<Cell> cellUsed = []; private readonly List<Cell> cellUsed = [];
@ -274,7 +272,7 @@ namespace QwirkleClassLibrary.Games
{ {
foreach (var p in players) foreach (var p in players)
{ {
for (int j = 0; j < 6; j++) for (int j = 0; j < 1; j++) // 6
{ {
if (bag != null && p.Tiles.Count < 6) if (bag != null && p.Tiles.Count < 6)
{ {
@ -761,7 +759,7 @@ namespace QwirkleClassLibrary.Games
{ {
List<int> playerTilesBagPos = []; List<int> playerTilesBagPos = [];
if (bag!.TilesBag!.Count == 0) if (bag!.TilesBag!.Count <= 12)
{ {
for (int i = 0; i < players.Count; i++) for (int i = 0; i < players.Count; i++)
{ {
@ -830,6 +828,7 @@ namespace QwirkleClassLibrary.Games
players.Clear(); players.Clear();
scoreBoard.Clear(); scoreBoard.Clear();
cellUsed.Clear(); cellUsed.Clear();
observableScoreBoard.Clear();
bag = null; bag = null;
board = CreateBoard(); board = CreateBoard();
GameRunning = false; GameRunning = false;

@ -1,7 +1,10 @@
using System; using QwirkleClassLibrary.Tiles;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq; using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.ExceptionServices; using System.Runtime.ExceptionServices;
using System.Runtime.Serialization; using System.Runtime.Serialization;
using System.Text; using System.Text;
@ -10,12 +13,27 @@ using System.Threading.Tasks;
namespace QwirkleClassLibrary.Players namespace QwirkleClassLibrary.Players
{ {
[DataContract] [DataContract]
public class Leaderboard public class Leaderboard : INotifyPropertyChanged
{ {
public ReadOnlyCollection<Score> Lb => leaderboard.AsReadOnly();
[DataMember] [DataMember]
private readonly List<Score> leaderboard = new(); private readonly ObservableCollection<Score> leaderboard = new();
public event PropertyChangedEventHandler? PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public ReadOnlyObservableCollection<Score> Lb
{
get
{
return (ReadOnlyObservableCollection<Score>)leaderboard.AsReadOnly();
}
}
/// <summary> /// <summary>
@ -57,11 +75,13 @@ namespace QwirkleClassLibrary.Players
if (first) if (first)
{ {
leaderboard[i].Victories++; leaderboard[i].Victories++;
OnPropertyChanged(nameof(leaderboard));
} }
if (pair.Value > leaderboard[i].Points) if (pair.Value > leaderboard[i].Points)
{ {
leaderboard[i].Points = pair.Value; leaderboard[i].Points = pair.Value;
OnPropertyChanged(nameof(leaderboard));
} }
} }
@ -74,6 +94,7 @@ namespace QwirkleClassLibrary.Players
} }
Score score = new Score(pair.Key, now, pair.Value, v); Score score = new Score(pair.Key, now, pair.Value, v);
leaderboard.Add(score); leaderboard.Add(score);
OnPropertyChanged(nameof(leaderboard));
} }
first = false; first = false;

@ -24,22 +24,28 @@ namespace QwirkleClassLibrary.Tiles
/// <exception cref="ArgumentException">Throw an exception if the number of copies is negative (impossible) or superior to 3 (contradiction with the rules).</exception> /// <exception cref="ArgumentException">Throw an exception if the number of copies is negative (impossible) or superior to 3 (contradiction with the rules).</exception>
public TileBag(int nbSet) public TileBag(int nbSet)
{ {
if (nbSet < 0 || nbSet > 3) /* if (nbSet < 0 || nbSet > 3)
{ {
throw new ArgumentException(nbSet.ToString()); throw new ArgumentException(nbSet.ToString());
} }
for (int i = 0; i < nbSet; i++) for (int i = 0; i < nbSet; i++)
{ {
foreach (Shape s in Enum.GetValues(typeof(Shape))) foreach (Shape s in Enum.GetValues(typeof(Shape)))
{ {
foreach (Color c in Enum.GetValues(typeof(Color))) foreach (Color c in Enum.GetValues(typeof(Color)))
{ {
Tile t = new(s, c); Tile t = new(s, c);
tiles.Add(t); tiles.Add(t);
} }
} }
} }*/
Tile t1 = new Tile(Shape.Club, Color.Red);
Tile t2 = new Tile(Shape.Round, Color.Orange);
tiles.Add(t1);
tiles.Add(t2);
Init(); Init();
} }

@ -2,6 +2,7 @@
using Microsoft.Maui.Controls; using Microsoft.Maui.Controls;
using Qwirkle.Pages; using Qwirkle.Pages;
using QwirkleClassLibrary.Games; using QwirkleClassLibrary.Games;
using QwirkleClassLibrary.Players;
namespace Qwirkle namespace Qwirkle
{ {
@ -17,9 +18,12 @@ namespace Qwirkle
Routing.RegisterRoute(nameof(Gameboard), typeof(Gameboard)); Routing.RegisterRoute(nameof(Gameboard), typeof(Gameboard));
Routing.RegisterRoute(nameof(Rules), typeof(Rules)); Routing.RegisterRoute(nameof(Rules), typeof(Rules));
Routing.RegisterRoute(nameof(MainPage), typeof(MainPage)); Routing.RegisterRoute(nameof(MainPage), typeof(MainPage));
Routing.RegisterRoute(nameof(Qwirkle.Pages.Leaderboard), typeof(Qwirkle.Pages.Leaderboard));
} }
public Game Game { get; set; } = new(); public Game Game { get; set; } = new();
public QwirkleClassLibrary.Players.Leaderboard LD { get; set; } = new();
} }
} }

@ -26,7 +26,8 @@
InfoClicked="OnInfoClicked" InfoClicked="OnInfoClicked"
/> />
<controls:ButtonShadow Text="Leaderboard"/> <controls:ButtonShadow Text="Leaderboard"
InfoClicked="OnCLeaderboardClicked"/>
<controls:ButtonShadow Text="Rules" <controls:ButtonShadow Text="Rules"
InfoClicked="OnRulesClicked"/> InfoClicked="OnRulesClicked"/>

@ -38,6 +38,11 @@ namespace Qwirkle
Navigation.PushAsync(new Credits()); Navigation.PushAsync(new Credits());
} }
public void OnCLeaderboardClicked(object sender, EventArgs e)
{
Navigation.PushAsync(new Leaderboard());
}
} }
} }

@ -9,6 +9,7 @@ using System.ComponentModel;
using Cell = QwirkleClassLibrary.Boards.Cell; using Cell = QwirkleClassLibrary.Boards.Cell;
using Color = Microsoft.Maui.Graphics.Color; using Color = Microsoft.Maui.Graphics.Color;
using System.Drawing; using System.Drawing;
using CommunityToolkit.Maui.Views;
namespace Qwirkle.Pages; namespace Qwirkle.Pages;
@ -42,9 +43,13 @@ public partial class Gameboard : ContentPage
private void Game_EndOfGameNotified(object? sender, EndOfGameNotifiedEventArgs e) private void Game_EndOfGameNotified(object? sender, EndOfGameNotifiedEventArgs e)
{ {
DisplayAlert("THE END.", "FAUT QU'ON PARLE DE CE QUE QU'ON VEUT FAIRE ICI !!!" ,"<3"); PopUpEnd();
Navigation.PushAsync(new MainPage()); Navigation.PushAsync(new MainPage());
game.ClearGame(); }
private async void PopUpEnd()
{
await this.ShowPopupAsync(new PopUpEndGame());
} }
private void OnDragStarting(object sender, DragStartingEventArgs e) private void OnDragStarting(object sender, DragStartingEventArgs e)
@ -107,12 +112,19 @@ public partial class Gameboard : ContentPage
game.DrawTiles(game.GetPlayingPlayer()); game.DrawTiles(game.GetPlayingPlayer());
} }
game.CheckGameOver(game.GetPlayingPlayer()); if (!game.CheckGameOver(game.GetPlayingPlayer()))
game.SetNextPlayer(); {
game.SetNextPlayer();
ChangeColorBC();
}
else
{
((App)Application.Current!).LD.AddScoreInLead(game.ScoreBoard);
game.ClearGame();
}
game.NextPlayerNotified -= Game_NextPlayerNotified; game.NextPlayerNotified -= Game_NextPlayerNotified;
game.EndOfGameNotified -= Game_EndOfGameNotified; game.EndOfGameNotified -= Game_EndOfGameNotified;
ChangeColorBC();
} }
private void ChangeColorBC() private void ChangeColorBC()

@ -0,0 +1,55 @@
<?xml version="1.0" encoding="utf-8" ?>
<toolkit:Popup xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Qwirkle.PopUpEndGame"
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
x:Name="root"
CanBeDismissedByTappingOutsideOfPopup="False"
>
<VerticalStackLayout HeightRequest="400" WidthRequest="500">
<Label
Text="THE END :("
Style="{StaticResource SuperTitle}"
FontSize="Medium"
/>
<Label Text="THE WINNER IS :"></Label>
<Label Text="{Binding ScoreboardList[0].Key, Source={x:Reference root}}" Style="{StaticResource SuperTitle}" TextColor="HotPink" FontSize="Medium"></Label>
<CollectionView ItemsSource="{Binding ScoreboardList}" BindingContext="{x:Reference root}">
<CollectionView.ItemsLayout>
<GridItemsLayout Orientation="Vertical"/>
</CollectionView.ItemsLayout>
<CollectionView.ItemTemplate>
<DataTemplate>
<StackLayout>
<Grid ColumnDefinitions="4*, auto, 2*"
RowDefinitions="50">
<Label
Grid.Column="0"
Text="{Binding Key}"
Style="{StaticResource ContentTab}"/>
<Rectangle
Style="{StaticResource RectangleTab}"
Grid.Column="1"/>
<Label
Grid.Column="2"
Text="{Binding Value}"
Style="{StaticResource ContentTab}"/>
</Grid>
<Rectangle/>
</StackLayout>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
<Button Text="Skip" Style="{StaticResource GameButton}" Clicked="OnButtonNextClick"></Button>
</VerticalStackLayout>
</toolkit:Popup>

@ -0,0 +1,38 @@
using CommunityToolkit.Maui.Views;
using QwirkleClassLibrary.Games;
using System.Collections.ObjectModel;
namespace Qwirkle;
public partial class PopUpEndGame : Popup
{
public PopUpEndGame()
{
InitializeComponent();
var scoreboard = game.ObservableScoreBoard.OrderByDescending(x => x.Value).ThenBy(x => x.Key);
ScoreboardList = new ObservableCollection<KeyValuePair<string, int>>(scoreboard);
}
private Game game = ((App)Application.Current!).Game;
private ObservableCollection<KeyValuePair<string, int>>? scoreboardList;
public ObservableCollection<KeyValuePair<string, int>>? ScoreboardList
{
get => scoreboardList;
set
{
if (scoreboardList != value)
{
scoreboardList = value;
OnPropertyChanged(nameof(ScoreboardList));
}
}
}
public async void OnButtonNextClick(object sender, EventArgs e)
{
await CloseAsync();
}
}

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 586 KiB

@ -1,27 +0,0 @@
<?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.ScoreboardLine"
x:Name="root">
<StackLayout>
<Grid ColumnDefinitions="4*, auto, 2*"
RowDefinitions="50">
<Label
Grid.Column="0"
Text="{Binding Nameplayer, Source={x:Reference root}}"
Style="{StaticResource ContentTab}"/>
<Rectangle
Style="{StaticResource RectangleTab}"
Grid.Column="1"/>
<Label
Grid.Column="2"
Text="{Binding Score, Source={x:Reference root}}"
Style="{StaticResource ContentTab}"/>
</Grid>
<Rectangle/>
</StackLayout>
</ContentView>

@ -1,43 +0,0 @@
namespace Qwirkle.Views
{
public partial class ScoreboardLine : ContentView
{
public static readonly BindableProperty NameplayerProperty =
BindableProperty.Create(nameof(Nameplayer), typeof(string), typeof(ScoreboardLine), default(string), propertyChanged: OnPlayerChanged);
public string Nameplayer
{
get => (string)GetValue(NameplayerProperty);
set => SetValue(NameplayerProperty, value);
}
private static void OnPlayerChanged(BindableObject bindable, object oldValue, object newValue)
{
var bin = (ScoreboardLine)bindable;
bin.OnPropertyChanged(nameof(Nameplayer));
}
public static readonly BindableProperty ScoreProperty =
BindableProperty.Create(nameof(Score), typeof(int), typeof(ScoreboardLine), default(int), propertyChanged: OnScoreChanged);
public int Score
{
get => (int)GetValue(ScoreProperty);
set => SetValue(ScoreProperty, value);
}
private static void OnScoreChanged(BindableObject bindable, object oldValue, object newValue)
{
var bin = (ScoreboardLine)bindable;
bin.OnPropertyChanged(nameof(Score));
}
public ScoreboardLine()
{
InitializeComponent();
BindingContext = this;
}
}
}
Loading…
Cancel
Save