diff --git a/Qwirkle/Files/LeaderBoard.json b/Qwirkle/Files/LeaderBoard.json index 176dc08..fbec232 100644 --- a/Qwirkle/Files/LeaderBoard.json +++ b/Qwirkle/Files/LeaderBoard.json @@ -1 +1 @@ -2024-05-31T00:00:00+02:00Jérémy012024-05-31T00:00:00+02:00Jules00 \ No newline at end of file +{"leaderboard":[]} \ No newline at end of file diff --git a/Qwirkle/Files/game.json b/Qwirkle/Files/game.json index 9f0bf08..d4f31f8 100644 --- a/Qwirkle/Files/game.json +++ b/Qwirkle/Files/game.json @@ -1 +1,1426 @@ -true000102030405060708090100110120130141011121314151617181911011111211311420212223242526272829210211212213214303132333435363738393103113123133144041424344454647484941041141241341450515253545556575859510511512513514606162636465666768696106116126136147071727374757677787971071171271371480818283848586878889810811812813814909192939495969798999109119129139141001011021031041051061071081091010101110121013101411011111211311411511611711811911101111111211131114falseJulesPurpleClubRedClubRedRhombusPurpleRoundPurpleStarPurpleStartrueJérémyGreenClubBlueShurikenGreenSquareOrangeStarOrangeClubBlueClubfalseJulesPurpleClubRedClubRedRhombusPurpleRoundPurpleStarPurpleStar0trueJérémyGreenClubBlueShurikenGreenSquareOrangeStarOrangeClubBlueClub0 \ No newline at end of file +{ + "GameRunning": true, + "bag": { + "tiles": [ + { + "color": 0, + "shape": 0 + }, + { + "color": 1, + "shape": 0 + }, + { + "color": 2, + "shape": 0 + }, + { + "color": 3, + "shape": 0 + }, + { + "color": 4, + "shape": 0 + }, + { + "color": 5, + "shape": 0 + }, + { + "color": 1, + "shape": 1 + }, + { + "color": 2, + "shape": 1 + }, + { + "color": 3, + "shape": 1 + }, + { + "color": 4, + "shape": 1 + }, + { + "color": 5, + "shape": 1 + }, + { + "color": 0, + "shape": 2 + }, + { + "color": 1, + "shape": 2 + }, + { + "color": 2, + "shape": 2 + }, + { + "color": 3, + "shape": 2 + }, + { + "color": 4, + "shape": 2 + }, + { + "color": 5, + "shape": 2 + }, + { + "color": 0, + "shape": 3 + }, + { + "color": 1, + "shape": 3 + }, + { + "color": 2, + "shape": 3 + }, + { + "color": 4, + "shape": 3 + }, + { + "color": 5, + "shape": 3 + }, + { + "color": 1, + "shape": 4 + }, + { + "color": 2, + "shape": 4 + }, + { + "color": 3, + "shape": 4 + }, + { + "color": 4, + "shape": 4 + }, + { + "color": 5, + "shape": 4 + }, + { + "color": 0, + "shape": 5 + }, + { + "color": 1, + "shape": 5 + }, + { + "color": 2, + "shape": 5 + }, + { + "color": 3, + "shape": 5 + }, + { + "color": 4, + "shape": 5 + }, + { + "color": 5, + "shape": 5 + }, + { + "color": 0, + "shape": 0 + }, + { + "color": 1, + "shape": 0 + }, + { + "color": 2, + "shape": 0 + }, + { + "color": 3, + "shape": 0 + }, + { + "color": 4, + "shape": 0 + }, + { + "color": 5, + "shape": 0 + }, + { + "color": 0, + "shape": 1 + }, + { + "color": 1, + "shape": 1 + }, + { + "color": 2, + "shape": 1 + }, + { + "color": 3, + "shape": 1 + }, + { + "color": 4, + "shape": 1 + }, + { + "color": 5, + "shape": 1 + }, + { + "color": 0, + "shape": 2 + }, + { + "color": 1, + "shape": 2 + }, + { + "color": 2, + "shape": 2 + }, + { + "color": 3, + "shape": 2 + }, + { + "color": 4, + "shape": 2 + }, + { + "color": 5, + "shape": 2 + }, + { + "color": 0, + "shape": 3 + }, + { + "color": 1, + "shape": 3 + }, + { + "color": 2, + "shape": 3 + }, + { + "color": 3, + "shape": 3 + }, + { + "color": 1, + "shape": 4 + }, + { + "color": 2, + "shape": 4 + }, + { + "color": 3, + "shape": 4 + }, + { + "color": 4, + "shape": 4 + }, + { + "color": 5, + "shape": 4 + }, + { + "color": 0, + "shape": 5 + }, + { + "color": 1, + "shape": 5 + }, + { + "color": 2, + "shape": 5 + }, + { + "color": 3, + "shape": 5 + }, + { + "color": 4, + "shape": 5 + }, + { + "color": 3, + "shape": 0 + }, + { + "color": 4, + "shape": 0 + }, + { + "color": 5, + "shape": 0 + }, + { + "color": 0, + "shape": 1 + }, + { + "color": 1, + "shape": 1 + }, + { + "color": 2, + "shape": 1 + }, + { + "color": 3, + "shape": 1 + }, + { + "color": 4, + "shape": 1 + }, + { + "color": 5, + "shape": 1 + }, + { + "color": 0, + "shape": 2 + }, + { + "color": 1, + "shape": 2 + }, + { + "color": 2, + "shape": 2 + }, + { + "color": 3, + "shape": 2 + }, + { + "color": 4, + "shape": 2 + }, + { + "color": 5, + "shape": 2 + }, + { + "color": 0, + "shape": 3 + }, + { + "color": 1, + "shape": 3 + }, + { + "color": 4, + "shape": 3 + }, + { + "color": 5, + "shape": 3 + }, + { + "color": 0, + "shape": 4 + }, + { + "color": 1, + "shape": 4 + }, + { + "color": 2, + "shape": 4 + }, + { + "color": 4, + "shape": 4 + }, + { + "color": 5, + "shape": 4 + }, + { + "color": 0, + "shape": 5 + }, + { + "color": 1, + "shape": 5 + }, + { + "color": 2, + "shape": 5 + }, + { + "color": 4, + "shape": 5 + }, + { + "color": 5, + "shape": 5 + } + ] + }, + "board": { + "Columns": 15, + "Rows": 12, + "cells": [ + { + "Tile": { + "color": 3, + "shape": 4 + }, + "x": 0, + "y": 0 + }, + { + "Tile": null, + "x": 0, + "y": 1 + }, + { + "Tile": null, + "x": 0, + "y": 2 + }, + { + "Tile": null, + "x": 0, + "y": 3 + }, + { + "Tile": null, + "x": 0, + "y": 4 + }, + { + "Tile": null, + "x": 0, + "y": 5 + }, + { + "Tile": null, + "x": 0, + "y": 6 + }, + { + "Tile": null, + "x": 0, + "y": 7 + }, + { + "Tile": null, + "x": 0, + "y": 8 + }, + { + "Tile": null, + "x": 0, + "y": 9 + }, + { + "Tile": null, + "x": 0, + "y": 10 + }, + { + "Tile": null, + "x": 0, + "y": 11 + }, + { + "Tile": null, + "x": 0, + "y": 12 + }, + { + "Tile": null, + "x": 0, + "y": 13 + }, + { + "Tile": null, + "x": 0, + "y": 14 + }, + { + "Tile": { + "color": 3, + "shape": 5 + }, + "x": 1, + "y": 0 + }, + { + "Tile": null, + "x": 1, + "y": 1 + }, + { + "Tile": null, + "x": 1, + "y": 2 + }, + { + "Tile": null, + "x": 1, + "y": 3 + }, + { + "Tile": null, + "x": 1, + "y": 4 + }, + { + "Tile": null, + "x": 1, + "y": 5 + }, + { + "Tile": null, + "x": 1, + "y": 6 + }, + { + "Tile": null, + "x": 1, + "y": 7 + }, + { + "Tile": null, + "x": 1, + "y": 8 + }, + { + "Tile": null, + "x": 1, + "y": 9 + }, + { + "Tile": null, + "x": 1, + "y": 10 + }, + { + "Tile": null, + "x": 1, + "y": 11 + }, + { + "Tile": null, + "x": 1, + "y": 12 + }, + { + "Tile": null, + "x": 1, + "y": 13 + }, + { + "Tile": null, + "x": 1, + "y": 14 + }, + { + "Tile": null, + "x": 2, + "y": 0 + }, + { + "Tile": null, + "x": 2, + "y": 1 + }, + { + "Tile": null, + "x": 2, + "y": 2 + }, + { + "Tile": null, + "x": 2, + "y": 3 + }, + { + "Tile": null, + "x": 2, + "y": 4 + }, + { + "Tile": null, + "x": 2, + "y": 5 + }, + { + "Tile": null, + "x": 2, + "y": 6 + }, + { + "Tile": null, + "x": 2, + "y": 7 + }, + { + "Tile": null, + "x": 2, + "y": 8 + }, + { + "Tile": null, + "x": 2, + "y": 9 + }, + { + "Tile": null, + "x": 2, + "y": 10 + }, + { + "Tile": null, + "x": 2, + "y": 11 + }, + { + "Tile": null, + "x": 2, + "y": 12 + }, + { + "Tile": null, + "x": 2, + "y": 13 + }, + { + "Tile": null, + "x": 2, + "y": 14 + }, + { + "Tile": null, + "x": 3, + "y": 0 + }, + { + "Tile": null, + "x": 3, + "y": 1 + }, + { + "Tile": null, + "x": 3, + "y": 2 + }, + { + "Tile": null, + "x": 3, + "y": 3 + }, + { + "Tile": null, + "x": 3, + "y": 4 + }, + { + "Tile": null, + "x": 3, + "y": 5 + }, + { + "Tile": null, + "x": 3, + "y": 6 + }, + { + "Tile": null, + "x": 3, + "y": 7 + }, + { + "Tile": null, + "x": 3, + "y": 8 + }, + { + "Tile": null, + "x": 3, + "y": 9 + }, + { + "Tile": null, + "x": 3, + "y": 10 + }, + { + "Tile": null, + "x": 3, + "y": 11 + }, + { + "Tile": null, + "x": 3, + "y": 12 + }, + { + "Tile": null, + "x": 3, + "y": 13 + }, + { + "Tile": null, + "x": 3, + "y": 14 + }, + { + "Tile": null, + "x": 4, + "y": 0 + }, + { + "Tile": null, + "x": 4, + "y": 1 + }, + { + "Tile": null, + "x": 4, + "y": 2 + }, + { + "Tile": null, + "x": 4, + "y": 3 + }, + { + "Tile": null, + "x": 4, + "y": 4 + }, + { + "Tile": null, + "x": 4, + "y": 5 + }, + { + "Tile": null, + "x": 4, + "y": 6 + }, + { + "Tile": null, + "x": 4, + "y": 7 + }, + { + "Tile": null, + "x": 4, + "y": 8 + }, + { + "Tile": null, + "x": 4, + "y": 9 + }, + { + "Tile": null, + "x": 4, + "y": 10 + }, + { + "Tile": null, + "x": 4, + "y": 11 + }, + { + "Tile": null, + "x": 4, + "y": 12 + }, + { + "Tile": null, + "x": 4, + "y": 13 + }, + { + "Tile": null, + "x": 4, + "y": 14 + }, + { + "Tile": null, + "x": 5, + "y": 0 + }, + { + "Tile": null, + "x": 5, + "y": 1 + }, + { + "Tile": null, + "x": 5, + "y": 2 + }, + { + "Tile": null, + "x": 5, + "y": 3 + }, + { + "Tile": null, + "x": 5, + "y": 4 + }, + { + "Tile": null, + "x": 5, + "y": 5 + }, + { + "Tile": null, + "x": 5, + "y": 6 + }, + { + "Tile": null, + "x": 5, + "y": 7 + }, + { + "Tile": null, + "x": 5, + "y": 8 + }, + { + "Tile": null, + "x": 5, + "y": 9 + }, + { + "Tile": null, + "x": 5, + "y": 10 + }, + { + "Tile": null, + "x": 5, + "y": 11 + }, + { + "Tile": null, + "x": 5, + "y": 12 + }, + { + "Tile": null, + "x": 5, + "y": 13 + }, + { + "Tile": null, + "x": 5, + "y": 14 + }, + { + "Tile": null, + "x": 6, + "y": 0 + }, + { + "Tile": null, + "x": 6, + "y": 1 + }, + { + "Tile": null, + "x": 6, + "y": 2 + }, + { + "Tile": null, + "x": 6, + "y": 3 + }, + { + "Tile": null, + "x": 6, + "y": 4 + }, + { + "Tile": null, + "x": 6, + "y": 5 + }, + { + "Tile": null, + "x": 6, + "y": 6 + }, + { + "Tile": null, + "x": 6, + "y": 7 + }, + { + "Tile": null, + "x": 6, + "y": 8 + }, + { + "Tile": null, + "x": 6, + "y": 9 + }, + { + "Tile": null, + "x": 6, + "y": 10 + }, + { + "Tile": null, + "x": 6, + "y": 11 + }, + { + "Tile": null, + "x": 6, + "y": 12 + }, + { + "Tile": null, + "x": 6, + "y": 13 + }, + { + "Tile": null, + "x": 6, + "y": 14 + }, + { + "Tile": null, + "x": 7, + "y": 0 + }, + { + "Tile": null, + "x": 7, + "y": 1 + }, + { + "Tile": null, + "x": 7, + "y": 2 + }, + { + "Tile": null, + "x": 7, + "y": 3 + }, + { + "Tile": null, + "x": 7, + "y": 4 + }, + { + "Tile": null, + "x": 7, + "y": 5 + }, + { + "Tile": null, + "x": 7, + "y": 6 + }, + { + "Tile": null, + "x": 7, + "y": 7 + }, + { + "Tile": null, + "x": 7, + "y": 8 + }, + { + "Tile": null, + "x": 7, + "y": 9 + }, + { + "Tile": null, + "x": 7, + "y": 10 + }, + { + "Tile": null, + "x": 7, + "y": 11 + }, + { + "Tile": null, + "x": 7, + "y": 12 + }, + { + "Tile": null, + "x": 7, + "y": 13 + }, + { + "Tile": null, + "x": 7, + "y": 14 + }, + { + "Tile": null, + "x": 8, + "y": 0 + }, + { + "Tile": null, + "x": 8, + "y": 1 + }, + { + "Tile": null, + "x": 8, + "y": 2 + }, + { + "Tile": null, + "x": 8, + "y": 3 + }, + { + "Tile": null, + "x": 8, + "y": 4 + }, + { + "Tile": null, + "x": 8, + "y": 5 + }, + { + "Tile": null, + "x": 8, + "y": 6 + }, + { + "Tile": null, + "x": 8, + "y": 7 + }, + { + "Tile": null, + "x": 8, + "y": 8 + }, + { + "Tile": null, + "x": 8, + "y": 9 + }, + { + "Tile": null, + "x": 8, + "y": 10 + }, + { + "Tile": null, + "x": 8, + "y": 11 + }, + { + "Tile": null, + "x": 8, + "y": 12 + }, + { + "Tile": null, + "x": 8, + "y": 13 + }, + { + "Tile": null, + "x": 8, + "y": 14 + }, + { + "Tile": null, + "x": 9, + "y": 0 + }, + { + "Tile": null, + "x": 9, + "y": 1 + }, + { + "Tile": null, + "x": 9, + "y": 2 + }, + { + "Tile": null, + "x": 9, + "y": 3 + }, + { + "Tile": null, + "x": 9, + "y": 4 + }, + { + "Tile": null, + "x": 9, + "y": 5 + }, + { + "Tile": null, + "x": 9, + "y": 6 + }, + { + "Tile": null, + "x": 9, + "y": 7 + }, + { + "Tile": null, + "x": 9, + "y": 8 + }, + { + "Tile": null, + "x": 9, + "y": 9 + }, + { + "Tile": null, + "x": 9, + "y": 10 + }, + { + "Tile": null, + "x": 9, + "y": 11 + }, + { + "Tile": null, + "x": 9, + "y": 12 + }, + { + "Tile": null, + "x": 9, + "y": 13 + }, + { + "Tile": null, + "x": 9, + "y": 14 + }, + { + "Tile": null, + "x": 10, + "y": 0 + }, + { + "Tile": null, + "x": 10, + "y": 1 + }, + { + "Tile": null, + "x": 10, + "y": 2 + }, + { + "Tile": null, + "x": 10, + "y": 3 + }, + { + "Tile": null, + "x": 10, + "y": 4 + }, + { + "Tile": null, + "x": 10, + "y": 5 + }, + { + "Tile": null, + "x": 10, + "y": 6 + }, + { + "Tile": null, + "x": 10, + "y": 7 + }, + { + "Tile": null, + "x": 10, + "y": 8 + }, + { + "Tile": null, + "x": 10, + "y": 9 + }, + { + "Tile": null, + "x": 10, + "y": 10 + }, + { + "Tile": null, + "x": 10, + "y": 11 + }, + { + "Tile": null, + "x": 10, + "y": 12 + }, + { + "Tile": null, + "x": 10, + "y": 13 + }, + { + "Tile": null, + "x": 10, + "y": 14 + }, + { + "Tile": null, + "x": 11, + "y": 0 + }, + { + "Tile": null, + "x": 11, + "y": 1 + }, + { + "Tile": null, + "x": 11, + "y": 2 + }, + { + "Tile": null, + "x": 11, + "y": 3 + }, + { + "Tile": null, + "x": 11, + "y": 4 + }, + { + "Tile": null, + "x": 11, + "y": 5 + }, + { + "Tile": null, + "x": 11, + "y": 6 + }, + { + "Tile": null, + "x": 11, + "y": 7 + }, + { + "Tile": null, + "x": 11, + "y": 8 + }, + { + "Tile": null, + "x": 11, + "y": 9 + }, + { + "Tile": null, + "x": 11, + "y": 10 + }, + { + "Tile": null, + "x": 11, + "y": 11 + }, + { + "Tile": null, + "x": 11, + "y": 12 + }, + { + "Tile": null, + "x": 11, + "y": 13 + }, + { + "Tile": null, + "x": 11, + "y": 14 + } + ] + }, + "cellUsed": [], + "players": [ + { + "IsPlaying": false, + "NameTag": "Jules", + "Tiles": [ + { + "color": 0, + "shape": 1 + }, + { + "color": 0, + "shape": 4 + }, + { + "color": 0, + "shape": 0 + }, + { + "color": 2, + "shape": 0 + }, + { + "color": 5, + "shape": 5 + }, + { + "color": 0, + "shape": 4 + } + ] + }, + { + "IsPlaying": true, + "NameTag": "Jérémy", + "Tiles": [ + { + "color": 4, + "shape": 3 + }, + { + "color": 3, + "shape": 3 + }, + { + "color": 1, + "shape": 0 + }, + { + "color": 2, + "shape": 3 + }, + { + "color": 3, + "shape": 3 + }, + { + "color": 5, + "shape": 3 + } + ] + } + ], + "scoreBoard": [ + { + "Key": { + "IsPlaying": false, + "NameTag": "Jules", + "Tiles": [ + { + "color": 0, + "shape": 1 + }, + { + "color": 0, + "shape": 4 + }, + { + "color": 0, + "shape": 0 + }, + { + "color": 2, + "shape": 0 + }, + { + "color": 5, + "shape": 5 + }, + { + "color": 0, + "shape": 4 + } + ] + }, + "Value": 2 + }, + { + "Key": { + "IsPlaying": true, + "NameTag": "Jérémy", + "Tiles": [ + { + "color": 4, + "shape": 3 + }, + { + "color": 3, + "shape": 3 + }, + { + "color": 1, + "shape": 0 + }, + { + "color": 2, + "shape": 3 + }, + { + "color": 3, + "shape": 3 + }, + { + "color": 5, + "shape": 3 + } + ] + }, + "Value": 0 + } + ] +} \ No newline at end of file diff --git a/Qwirkle/QwirkleClassLibrary/Boards/Board.cs b/Qwirkle/QwirkleClassLibrary/Boards/Board.cs index 2f0df94..76088ea 100644 --- a/Qwirkle/QwirkleClassLibrary/Boards/Board.cs +++ b/Qwirkle/QwirkleClassLibrary/Boards/Board.cs @@ -22,6 +22,7 @@ namespace QwirkleClassLibrary.Boards [DataMember] private ObservableCollection cells = new ObservableCollection(); + public ObservableCollection ReadCells { get { return cells; } @@ -32,8 +33,11 @@ namespace QwirkleClassLibrary.Boards } } - public int Rows { get; } - public int Columns { get; } + [DataMember] + public int Rows { get; set; } + + [DataMember] + public int Columns { get; set; } /// /// This is the constructor for the board. The parameters 'rows' and 'cols' are used to calculate the size of the board. diff --git a/Qwirkle/QwirkleClassLibrary/Games/Game.cs b/Qwirkle/QwirkleClassLibrary/Games/Game.cs index 6eee4f6..a7de103 100644 --- a/Qwirkle/QwirkleClassLibrary/Games/Game.cs +++ b/Qwirkle/QwirkleClassLibrary/Games/Game.cs @@ -20,6 +20,7 @@ namespace QwirkleClassLibrary.Games [DataContract] public class Game : IPlayer, IRules { + [DataMember] private TileBag? bag = null; [DataMember] @@ -27,6 +28,7 @@ namespace QwirkleClassLibrary.Games [DataMember] private Board board = new Board(15, 12); + public Board Board => board; public ReadOnlyCollection PlayerList => players.AsReadOnly(); @@ -39,8 +41,10 @@ namespace QwirkleClassLibrary.Games public ReadOnlyDictionary ScoreBoard => scoreBoard.AsReadOnly(); - public ReadOnlyCollection CellsUsed => cellUsed.AsReadOnly(); + [DataMember] private readonly List cellUsed = new(); + + public ReadOnlyCollection CellsUsed => cellUsed.AsReadOnly(); public event EventHandler? PlayerAddNotified; @@ -337,14 +341,9 @@ namespace QwirkleClassLibrary.Games return false; } - private bool TileInbag(Player player, Tile tile) + private static bool TileInbag(Player player, Tile tile) { - foreach (var t in player.Tiles) - { - if (ReferenceEquals(t, tile)) return true; - } - - return false; + return player.Tiles.Any(t => ReferenceEquals(t, tile)); } diff --git a/Qwirkle/QwirkleClassLibrary/Persistences/GamePersistenceJson.cs b/Qwirkle/QwirkleClassLibrary/Persistences/GamePersistenceJson.cs index da90959..83e409f 100644 --- a/Qwirkle/QwirkleClassLibrary/Persistences/GamePersistenceJson.cs +++ b/Qwirkle/QwirkleClassLibrary/Persistences/GamePersistenceJson.cs @@ -1,4 +1,4 @@ -using System.Runtime.Serialization; +using System.Runtime.Serialization.Json; using QwirkleClassLibrary.Games; namespace QwirkleClassLibrary.Persistences; @@ -7,7 +7,7 @@ public class GamePersistenceJson : IGamePersistence { public void SaveGame(Game game) { - var serializer = new DataContractSerializer(typeof(Game)); + var serializer = new DataContractJsonSerializer(typeof(Game)); using (Stream writer = File.Create("Game.json")) { @@ -17,7 +17,7 @@ public class GamePersistenceJson : IGamePersistence public Game LoadGame() { - var serializer = new DataContractSerializer(typeof(Game)); + var serializer = new DataContractJsonSerializer(typeof(Game)); using (Stream reader = File.OpenRead("Game.json")) { diff --git a/Qwirkle/QwirkleClassLibrary/Persistences/LeaderboardPersistenceJson.cs b/Qwirkle/QwirkleClassLibrary/Persistences/LeaderboardPersistenceJson.cs index decb648..82b41c1 100644 --- a/Qwirkle/QwirkleClassLibrary/Persistences/LeaderboardPersistenceJson.cs +++ b/Qwirkle/QwirkleClassLibrary/Persistences/LeaderboardPersistenceJson.cs @@ -1,4 +1,4 @@ -using System.Runtime.Serialization; +using System.Runtime.Serialization.Json; using QwirkleClassLibrary.Players; namespace QwirkleClassLibrary.Persistences; @@ -7,7 +7,7 @@ public class LeaderboardPersistenceJson : ILeaderboardPersistence { public void SaveLeaderboard(Leaderboard leaderboard) { - var serializer = new DataContractSerializer(typeof(Leaderboard)); + var serializer = new DataContractJsonSerializer(typeof(Leaderboard)); using (Stream writer = File.Create("Leaderboard.json")) { @@ -17,7 +17,7 @@ public class LeaderboardPersistenceJson : ILeaderboardPersistence public Leaderboard LoadLeaderboard() { - var serializer = new DataContractSerializer(typeof(Leaderboard)); + var serializer = new DataContractJsonSerializer(typeof(Leaderboard)); using (Stream reader = File.OpenRead("Leaderboard.json")) { diff --git a/Qwirkle/QwirkleClassLibrary/Players/Player.cs b/Qwirkle/QwirkleClassLibrary/Players/Player.cs index 2f7ae77..0274620 100644 --- a/Qwirkle/QwirkleClassLibrary/Players/Player.cs +++ b/Qwirkle/QwirkleClassLibrary/Players/Player.cs @@ -16,7 +16,7 @@ namespace QwirkleClassLibrary.Players public class Player : INotifyPropertyChanged { [DataMember] - public ObservableCollection Tiles { get; private set; } + public ObservableCollection Tiles { get; set; } public event PropertyChangedEventHandler? PropertyChanged; diff --git a/Qwirkle/QwirkleClassLibrary/Tiles/TileBag.cs b/Qwirkle/QwirkleClassLibrary/Tiles/TileBag.cs index c8f70d3..a1821e2 100644 --- a/Qwirkle/QwirkleClassLibrary/Tiles/TileBag.cs +++ b/Qwirkle/QwirkleClassLibrary/Tiles/TileBag.cs @@ -2,14 +2,18 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; namespace QwirkleClassLibrary.Tiles { + [DataContract] public class TileBag { public ReadOnlyCollection TilesBag { get; private set; } + + [DataMember] private readonly List tiles = new List(); /// diff --git a/Qwirkle/QwirkleConsoleApp/Program.cs b/Qwirkle/QwirkleConsoleApp/Program.cs index 49137d9..9f17631 100644 --- a/Qwirkle/QwirkleConsoleApp/Program.cs +++ b/Qwirkle/QwirkleConsoleApp/Program.cs @@ -394,8 +394,14 @@ static void MainGame() game.StartGame(); MainMenu(game); - - leaderboard.AddScoreInLead(game.ScoreBoard); + + foreach (var player in game.PlayerList) + { + if (game.CheckGameOver(player)) + { + leaderboard.AddScoreInLead(game.ScoreBoard); + } + } ILeaderboardPersistence leaderboardSave = new LeaderboardPersistenceJson(); leaderboardSave.SaveLeaderboard(leaderboard); diff --git a/Qwirkle/TestBase/TestPersistence.cs b/Qwirkle/TestBase/TestPersistence.cs new file mode 100644 index 0000000..8e435e9 --- /dev/null +++ b/Qwirkle/TestBase/TestPersistence.cs @@ -0,0 +1,42 @@ +using Xunit; +using QwirkleClassLibrary.Games; +using QwirkleClassLibrary.Persistences; +using System.IO; + +namespace TestBase +{ + public class TestPersistence + { + [Fact] + public void Test_SaveGame() + { + var game = new Game(); + + IGamePersistence gamePersistence = new GamePersistenceJson(); + gamePersistence.SaveGame(game); + + Assert.True(File.Exists("Game.json")); + } + + [Fact] + public void Test_LoadGame() + { + Directory.SetCurrentDirectory(Path.Combine(Directory.GetCurrentDirectory(), "..\\..\\..\\..\\Files")); + + var game = new Game(); + + game.AddPlayerInGame(["Jules", "Jérémy"]); + game.StartGame(); + + IGamePersistence gamePersistence = new GamePersistenceJson(); + gamePersistence.SaveGame(game); + + var loadedGame = gamePersistence.LoadGame(); + + Assert.True(game.Board.ReadCells.All(cell => + cell.GetX == loadedGame.Board.GetCell(cell.GetX, cell.GetY)!.GetX && + cell.GetY == loadedGame.Board.GetCell(cell.GetX, cell.GetY)!.GetY && + cell.IsFree == loadedGame.Board.GetCell(cell.GetX, cell.GetY)!.IsFree)); + } + } +} \ No newline at end of file