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 QwirkleClassLibrary.Games;
|
||||
|
||||
namespace QwirkleClassLibrary.Persistences;
|
||||
|
||||
public class GamePersistenceXml : IGamePersistence
|
||||
namespace QwirkleClassLibrary.Persistences
|
||||
{
|
||||
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),
|
||||
new DataContractSerializerSettings() { PreserveObjectReferences = true });
|
||||
|
||||
using (Stream writer = File.Create("Game.xml"))
|
||||
/// <summary>
|
||||
/// 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>
|
||||
/// <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()
|
||||
{
|
||||
var serializer = new DataContractSerializer(typeof(Game));
|
||||
|
||||
try
|
||||
{
|
||||
using (Stream reader = File.OpenRead("Game.xml"))
|
||||
using (Stream writer = File.Create("Game.xml"))
|
||||
{
|
||||
var newGame = serializer.ReadObject(reader) as Game;
|
||||
return newGame!;
|
||||
serializer.WriteObject(writer, game);
|
||||
}
|
||||
}
|
||||
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 QwirkleClassLibrary.Players;
|
||||
|
||||
namespace QwirkleClassLibrary.Persistences;
|
||||
|
||||
public class LeaderboardPersistenceJson : ILeaderboardPersistence
|
||||
namespace QwirkleClassLibrary.Persistences
|
||||
{
|
||||
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));
|
||||
|
||||
using (Stream writer = File.Create("Leaderboard.json"))
|
||||
/// <summary>
|
||||
/// As the name suggest, this class is used to save the data from the leaderboard.
|
||||
/// </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()
|
||||
{
|
||||
var serializer = new DataContractJsonSerializer(typeof(Leaderboard));
|
||||
|
||||
using (Stream reader = File.OpenRead("Leaderboard.json"))
|
||||
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()
|
||||
{
|
||||
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