Compare commits
No commits in common. 'master' and 'test_old_branch' have entirely different histories.
master
...
test_old_b
File diff suppressed because one or more lines are too long
@ -1,47 +1,36 @@
|
|||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
using QwirkleClassLibrary.Games;
|
using QwirkleClassLibrary.Games;
|
||||||
|
|
||||||
namespace QwirkleClassLibrary.Persistences
|
namespace QwirkleClassLibrary.Persistences;
|
||||||
|
|
||||||
|
public class GamePersistenceXml : IGamePersistence
|
||||||
{
|
{
|
||||||
/// <summary>
|
public void SaveGame(Game game)
|
||||||
/// This class takes care of managing persistence with regard to the information of the current game, allowing the last game played to be resumed even when returning to the menu or exiting the application.
|
|
||||||
/// </summary>
|
|
||||||
public class GamePersistenceXml : IGamePersistence
|
|
||||||
{
|
{
|
||||||
/// <summary>
|
var serializer = new DataContractSerializer(typeof(Game),
|
||||||
/// The main purpose of this method is to save the data from the game when the user quits the app, so players can continue it later.
|
new DataContractSerializerSettings() { PreserveObjectReferences = true });
|
||||||
/// </summary>
|
|
||||||
/// <param name="game"></param>
|
using (Stream writer = File.Create("Game.xml"))
|
||||||
public void SaveGame(Game game)
|
|
||||||
{
|
{
|
||||||
var serializer = new DataContractSerializer(typeof(Game),
|
serializer.WriteObject(writer, game);
|
||||||
new DataContractSerializerSettings() { PreserveObjectReferences = true });
|
}
|
||||||
|
}
|
||||||
|
|
||||||
using (Stream writer = File.Create("Game.xml"))
|
public Game LoadGame()
|
||||||
|
{
|
||||||
|
var serializer = new DataContractSerializer(typeof(Game));
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (Stream reader = File.OpenRead("Game.xml"))
|
||||||
{
|
{
|
||||||
serializer.WriteObject(writer, game);
|
var newGame = serializer.ReadObject(reader) as Game;
|
||||||
|
return newGame!;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// <summary>
|
catch
|
||||||
/// This method is used to retrieve the information needed to resume the last game launched on the application.
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>A Game.</returns>
|
|
||||||
public Game LoadGame()
|
|
||||||
{
|
{
|
||||||
var serializer = new DataContractSerializer(typeof(Game));
|
return new Game();
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
using (Stream reader = File.OpenRead("Game.xml"))
|
|
||||||
{
|
|
||||||
var newGame = serializer.ReadObject(reader) as Game;
|
|
||||||
return newGame!;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
return new Game();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,39 +1,27 @@
|
|||||||
using System.Runtime.Serialization.Json;
|
using System.Runtime.Serialization.Json;
|
||||||
using QwirkleClassLibrary.Players;
|
using QwirkleClassLibrary.Players;
|
||||||
|
|
||||||
namespace QwirkleClassLibrary.Persistences
|
namespace QwirkleClassLibrary.Persistences;
|
||||||
|
|
||||||
|
public class LeaderboardPersistenceJson : ILeaderboardPersistence
|
||||||
{
|
{
|
||||||
/// <summary>
|
public void SaveLeaderboard(Leaderboard leaderboard)
|
||||||
/// This is the persistence class for the leaderboard : it is in charge of managing all the parameters necessary for the backup and recovery of data concerning the leaderboard.
|
|
||||||
/// </summary>
|
|
||||||
public class LeaderboardPersistenceJson : ILeaderboardPersistence
|
|
||||||
{
|
{
|
||||||
/// <summary>
|
var serializer = new DataContractJsonSerializer(typeof(Leaderboard));
|
||||||
/// As the name suggest, this class is used to save the data from the leaderboard.
|
|
||||||
/// </summary>
|
using (Stream writer = File.Create("Leaderboard.json"))
|
||||||
/// <param name="leaderboard">The current leaderboard we want to save data from.</param>
|
|
||||||
public void SaveLeaderboard(Leaderboard leaderboard)
|
|
||||||
{
|
{
|
||||||
var serializer = new DataContractJsonSerializer(typeof(Leaderboard));
|
serializer.WriteObject(writer, leaderboard);
|
||||||
|
|
||||||
using (Stream writer = File.Create("Leaderboard.json"))
|
|
||||||
{
|
|
||||||
serializer.WriteObject(writer, leaderboard);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/// <summary>
|
}
|
||||||
/// This method is used to load the leaderboard into the app when the application starts.
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>Leaderboard</returns>
|
|
||||||
/// <exception cref="InvalidOperationException"></exception>
|
|
||||||
public Leaderboard LoadLeaderboard()
|
|
||||||
{
|
|
||||||
var serializer = new DataContractJsonSerializer(typeof(Leaderboard));
|
|
||||||
|
|
||||||
using (Stream reader = File.OpenRead("Leaderboard.json"))
|
public Leaderboard LoadLeaderboard()
|
||||||
{
|
{
|
||||||
return serializer.ReadObject(reader) as Leaderboard ?? throw new InvalidOperationException();
|
var serializer = new DataContractJsonSerializer(typeof(Leaderboard));
|
||||||
}
|
|
||||||
|
using (Stream reader = File.OpenRead("Leaderboard.json"))
|
||||||
|
{
|
||||||
|
return serializer.ReadObject(reader) as Leaderboard ?? throw new InvalidOperationException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,73 +1,77 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
|
||||||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
<ContentPage 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.Pages.Leaderboard"
|
x:Class="Qwirkle.Pages.Leaderboard"
|
||||||
xmlns:controls="clr-namespace:Qwirkle.Views"
|
xmlns:controls="clr-namespace:Qwirkle.Views"
|
||||||
Title="Leaderboard"
|
Title="Leaderboard">
|
||||||
x:Name="root">
|
|
||||||
|
|
||||||
<ScrollView>
|
<ScrollView>
|
||||||
<VerticalStackLayout Spacing="25" Padding="5, 5, 5, 10">
|
<VerticalStackLayout Spacing="25" Padding="5, 5, 5, 10">
|
||||||
<Grid Style="{StaticResource GridMain}">
|
<Grid Style="{StaticResource GridMain}">
|
||||||
<controls:GoBack></controls:GoBack>
|
<controls:GoBack></controls:GoBack>
|
||||||
<Label Text="Leaderboard"
|
<Label Text="Leaderboard"
|
||||||
Style="{StaticResource Title}" />
|
Style="{StaticResource Title}"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
<Border Style="{StaticResource TabBorder}">
|
<Border Style="{StaticResource TabBorder}">
|
||||||
|
|
||||||
<Border.Shadow>
|
<Border.Shadow>
|
||||||
<Shadow />
|
<Shadow/>
|
||||||
</Border.Shadow>
|
</Border.Shadow>
|
||||||
<Border.StrokeShape>
|
<Border.StrokeShape>
|
||||||
<RoundRectangle CornerRadius="3" />
|
<RoundRectangle CornerRadius="3"/>
|
||||||
</Border.StrokeShape>
|
</Border.StrokeShape>
|
||||||
|
|
||||||
<StackLayout>
|
<VerticalStackLayout>
|
||||||
<Grid ColumnDefinitions="4*, auto, 2*, auto, 2*, auto, 2*"
|
<controls:LeaderboardLine></controls:LeaderboardLine>
|
||||||
RowDefinitions="50">
|
<Rectangle/>
|
||||||
<Label
|
|
||||||
Text="Player tag"
|
<controls:LeaderboardLine></controls:LeaderboardLine>
|
||||||
Style="{StaticResource ContentTab}" />
|
<Rectangle/>
|
||||||
<Rectangle
|
|
||||||
Style="{StaticResource RectangleTab}"
|
<controls:LeaderboardLine></controls:LeaderboardLine>
|
||||||
Grid.Column="1" />
|
<Rectangle/>
|
||||||
<Label
|
|
||||||
Grid.Column="2"
|
<controls:LeaderboardLine></controls:LeaderboardLine>
|
||||||
Text="Date"
|
<Rectangle/>
|
||||||
Style="{StaticResource ContentTab}" />
|
|
||||||
<Rectangle
|
<controls:LeaderboardLine></controls:LeaderboardLine>
|
||||||
Style="{StaticResource RectangleTab}"
|
<Rectangle/>
|
||||||
Grid.Column="3" />
|
|
||||||
<Label
|
<controls:LeaderboardLine></controls:LeaderboardLine>
|
||||||
Grid.Column="4"
|
<Rectangle/>
|
||||||
Text="Points"
|
|
||||||
Style="{StaticResource ContentTab}" />
|
<controls:LeaderboardLine></controls:LeaderboardLine>
|
||||||
<Rectangle
|
<Rectangle/>
|
||||||
Style="{StaticResource RectangleTab}"
|
|
||||||
Grid.Column="5" />
|
<controls:LeaderboardLine></controls:LeaderboardLine>
|
||||||
<Label
|
<Rectangle/>
|
||||||
Grid.Column="6"
|
|
||||||
Style="{StaticResource ContentTab}"
|
<controls:LeaderboardLine></controls:LeaderboardLine>
|
||||||
Text="Victories" />
|
<Rectangle/>
|
||||||
</Grid>
|
|
||||||
|
<controls:LeaderboardLine></controls:LeaderboardLine>
|
||||||
<CollectionView ItemsSource="{Binding Lb}">
|
<Rectangle/>
|
||||||
<CollectionView.ItemsLayout>
|
|
||||||
<GridItemsLayout Orientation="Vertical" />
|
<controls:LeaderboardLine></controls:LeaderboardLine>
|
||||||
</CollectionView.ItemsLayout>
|
<Rectangle/>
|
||||||
<CollectionView.ItemTemplate>
|
|
||||||
<DataTemplate>
|
<controls:LeaderboardLine></controls:LeaderboardLine>
|
||||||
<controls:LeaderboardLine PlayerName="{Binding PlayerName}" Date="{Binding Date}"
|
<Rectangle/>
|
||||||
Points="{Binding Points}" Victories="{Binding Victories}" />
|
|
||||||
</DataTemplate>
|
<controls:LeaderboardLine></controls:LeaderboardLine>
|
||||||
</CollectionView.ItemTemplate>
|
<Rectangle/>
|
||||||
</CollectionView>
|
|
||||||
|
<controls:LeaderboardLine></controls:LeaderboardLine>
|
||||||
</StackLayout>
|
<Rectangle/>
|
||||||
|
|
||||||
|
<controls:LeaderboardLine></controls:LeaderboardLine>
|
||||||
|
</VerticalStackLayout>
|
||||||
</Border>
|
</Border>
|
||||||
|
|
||||||
</VerticalStackLayout>
|
</VerticalStackLayout>
|
||||||
|
|
||||||
|
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
|
||||||
</ContentPage>
|
</ContentPage>
|
@ -1,28 +0,0 @@
|
|||||||
<?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"
|
|
||||||
xmlns:controls="clr-namespace:Qwirkle.Views"
|
|
||||||
>
|
|
||||||
|
|
||||||
<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>
|
|
||||||
|
|
||||||
<controls:Scoreboard></controls:Scoreboard>
|
|
||||||
|
|
||||||
<Button Text="Skip" Style="{StaticResource GameButton}" Clicked="OnButtonNextClick"></Button>
|
|
||||||
|
|
||||||
</VerticalStackLayout>
|
|
||||||
</toolkit:Popup>
|
|
@ -1,40 +0,0 @@
|
|||||||
using CommunityToolkit.Maui.Views;
|
|
||||||
using Microsoft.Maui.Controls;
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
Close();
|
|
||||||
await Shell.Current.GoToAsync("MainPage");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"profiles": {
|
"profiles": {
|
||||||
"Windows Machine": {
|
"Windows Machine": {
|
||||||
"commandName": "Project",
|
"commandName": "MsixPackage",
|
||||||
"nativeDebugging": false
|
"nativeDebugging": false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Before Width: | Height: | Size: 591 KiB After Width: | Height: | Size: 228 B |
Before Width: | Height: | Size: 586 KiB |
Before Width: | Height: | Size: 38 KiB |
@ -1,42 +1,42 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
<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.LeaderboardLine"
|
x:Class="Qwirkle.Views.LeaderboardLine">
|
||||||
x:Name="root">
|
|
||||||
|
|
||||||
<Grid ColumnDefinitions="4*, auto, 2*, auto, 2*, auto, 2*"
|
<Grid ColumnDefinitions="4*, auto, 2*, auto, 2*, auto, 2*"
|
||||||
RowDefinitions="50">
|
RowDefinitions="50">
|
||||||
|
|
||||||
<Label
|
<Label
|
||||||
Text="{Binding PlayerName}"
|
Text="Player Tag"
|
||||||
Style="{StaticResource ContentTab}"/>
|
Style="{StaticResource ContentTab}"
|
||||||
|
/>
|
||||||
<Rectangle
|
<Rectangle
|
||||||
Style="{StaticResource RectangleTab}"
|
Style="{StaticResource RectangleTab}"
|
||||||
Grid.Column="1"/>
|
Grid.Column="1"/>
|
||||||
|
|
||||||
<Label
|
<Label
|
||||||
Grid.Column="2"
|
Grid.Column="2"
|
||||||
Text="{Binding Date, StringFormat='{0:MM/dd/yyyy}'}"
|
Text="Date"
|
||||||
Style="{StaticResource ContentTab}"/>
|
Style="{StaticResource ContentTab}"/>
|
||||||
|
|
||||||
<Rectangle
|
<Rectangle
|
||||||
Style="{StaticResource RectangleTab}"
|
Style="{StaticResource RectangleTab}"
|
||||||
Grid.Column="3"/>
|
Grid.Column="3"/>
|
||||||
|
|
||||||
<Label
|
<Label
|
||||||
Grid.Column="4"
|
Grid.Column="4"
|
||||||
Text="{Binding Points}"
|
Text="Points"
|
||||||
Style="{StaticResource ContentTab}"/>
|
Style="{StaticResource ContentTab}"/>
|
||||||
|
|
||||||
<Rectangle
|
<Rectangle
|
||||||
Style="{StaticResource RectangleTab}"
|
Style="{StaticResource RectangleTab}"
|
||||||
Grid.Column="5"/>
|
Grid.Column="5"/>
|
||||||
|
|
||||||
<Label
|
<Label
|
||||||
Grid.Column="6"
|
Grid.Column="6"
|
||||||
Style="{StaticResource ContentTab}"
|
Style="{StaticResource ContentTab}"
|
||||||
Text="{Binding Victories}"/>
|
Text="Victories"
|
||||||
|
/>
|
||||||
|
|
||||||
</Grid>
|
</Grid>
|
||||||
</ContentView>
|
</ContentView>
|
@ -0,0 +1,27 @@
|
|||||||
|
<?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>
|
@ -0,0 +1,43 @@
|
|||||||
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
Loading…
Reference in new issue