You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
788 B
27 lines
788 B
using System.Runtime.Serialization;
|
|
using QwirkleClassLibrary.Players;
|
|
|
|
namespace QwirkleClassLibrary.Persistences;
|
|
|
|
public class LeaderboardPersistence
|
|
{
|
|
public void SaveLeaderboard(Leaderboard leaderboard)
|
|
{
|
|
var leaderboardSerializer = new DataContractSerializer(typeof(Leaderboard));
|
|
|
|
using (Stream s = File.Create("LeaderBoard.json "))
|
|
{
|
|
leaderboardSerializer.WriteObject(s, leaderboard);
|
|
}
|
|
}
|
|
|
|
public Leaderboard LoadLeaderboard()
|
|
{
|
|
var leaderboardSerializer = new DataContractSerializer(typeof(Leaderboard));
|
|
|
|
using (Stream s = File.OpenRead("LeaderBoard.json"))
|
|
{
|
|
return leaderboardSerializer.ReadObject(s) as Leaderboard ?? throw new NullReferenceException();
|
|
}
|
|
}
|
|
} |