more and more documentation, again
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
ffbd8aba48
commit
d24b19e757
@ -1,36 +1,47 @@
|
|||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
using QwirkleClassLibrary.Games;
|
using QwirkleClassLibrary.Games;
|
||||||
|
|
||||||
namespace QwirkleClassLibrary.Persistences;
|
namespace QwirkleClassLibrary.Persistences
|
||||||
|
|
||||||
public class GamePersistenceXml : IGamePersistence
|
|
||||||
{
|
{
|
||||||
public void SaveGame(Game game)
|
/// <summary>
|
||||||
|
/// 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
|
||||||
{
|
{
|
||||||
var serializer = new DataContractSerializer(typeof(Game),
|
/// <summary>
|
||||||
new DataContractSerializerSettings() { PreserveObjectReferences = true });
|
/// 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.
|
||||||
|
/// </summary>
|
||||||
using (Stream writer = File.Create("Game.xml"))
|
/// <param name="game"></param>
|
||||||
|
public void SaveGame(Game game)
|
||||||
{
|
{
|
||||||
serializer.WriteObject(writer, game);
|
var serializer = new DataContractSerializer(typeof(Game),
|
||||||
}
|
new DataContractSerializerSettings() { PreserveObjectReferences = true });
|
||||||
}
|
|
||||||
|
|
||||||
public Game LoadGame()
|
using (Stream writer = File.Create("Game.xml"))
|
||||||
{
|
|
||||||
var serializer = new DataContractSerializer(typeof(Game));
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
using (Stream reader = File.OpenRead("Game.xml"))
|
|
||||||
{
|
{
|
||||||
var newGame = serializer.ReadObject(reader) as Game;
|
serializer.WriteObject(writer, game);
|
||||||
return newGame!;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch
|
/// <summary>
|
||||||
|
/// 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()
|
||||||
{
|
{
|
||||||
return new Game();
|
var serializer = new DataContractSerializer(typeof(Game));
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (Stream reader = File.OpenRead("Game.xml"))
|
||||||
|
{
|
||||||
|
var newGame = serializer.ReadObject(reader) as Game;
|
||||||
|
return newGame!;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return new Game();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,27 +1,39 @@
|
|||||||
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
|
|
||||||
{
|
{
|
||||||
public void SaveLeaderboard(Leaderboard leaderboard)
|
/// <summary>
|
||||||
|
/// 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
|
||||||
{
|
{
|
||||||
var serializer = new DataContractJsonSerializer(typeof(Leaderboard));
|
/// <summary>
|
||||||
|
/// As the name suggest, this class is used to save the data from the leaderboard.
|
||||||
using (Stream writer = File.Create("Leaderboard.json"))
|
/// </summary>
|
||||||
|
/// <param name="leaderboard">The current leaderboard we want to save data from.</param>
|
||||||
|
public void SaveLeaderboard(Leaderboard leaderboard)
|
||||||
{
|
{
|
||||||
serializer.WriteObject(writer, leaderboard);
|
var serializer = new DataContractJsonSerializer(typeof(Leaderboard));
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Leaderboard LoadLeaderboard()
|
using (Stream writer = File.Create("Leaderboard.json"))
|
||||||
{
|
{
|
||||||
var serializer = new DataContractJsonSerializer(typeof(Leaderboard));
|
serializer.WriteObject(writer, leaderboard);
|
||||||
|
}
|
||||||
using (Stream reader = File.OpenRead("Leaderboard.json"))
|
}
|
||||||
|
/// <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()
|
||||||
{
|
{
|
||||||
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in new issue