From 020fd61af37eaaac81d7b930be15f8c350f28b7d Mon Sep 17 00:00:00 2001 From: aldrikboy Date: Mon, 25 Dec 2017 14:07:42 +0100 Subject: I dab everyday --- Penguloon/UserdataManager.cs | 50 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Penguloon/UserdataManager.cs (limited to 'Penguloon/UserdataManager.cs') diff --git a/Penguloon/UserdataManager.cs b/Penguloon/UserdataManager.cs new file mode 100644 index 0000000..872ab1d --- /dev/null +++ b/Penguloon/UserdataManager.cs @@ -0,0 +1,50 @@ +using Android.Content; +using Java.IO; +using System; +using System.Linq; + + +namespace Penguloon +{ + public static class UserdataManager + { + public static int TotalKills { get; set; } + public static int TotalMoneySpent { get; set; } + public static int GamesPlayed { get; set; } + + public static int HighestRound { get; set; } + public static int HighestKills { get; set; } + + public static void WriteData(Context context) + { + File file = new File(context.CacheDir, "userdata.txt"); + using (var streamWriter = new System.IO.StreamWriter(file.AbsolutePath, false)) + { + streamWriter.WriteLine(TotalKills.ToString()); + streamWriter.WriteLine(TotalMoneySpent.ToString()); + streamWriter.WriteLine(GamesPlayed.ToString()); + streamWriter.WriteLine(HighestRound.ToString()); + streamWriter.WriteLine(HighestKills.ToString()); + } + } + + public static void ReadData(Context context) + { + File file = new File(context.CacheDir, "userdata.txt"); + + if (!file.Exists()) + WriteData(context); + + using (var streamReader = new System.IO.StreamReader(file.AbsolutePath, true)) + { + var lines = streamReader.ReadToEnd().Split(new string[] { "\n" }, StringSplitOptions.None); + + TotalKills = int.Parse(lines[0]); + TotalMoneySpent = int.Parse(lines[1]); + GamesPlayed = int.Parse(lines[2]); + HighestRound = int.Parse(lines[3]); + HighestKills = int.Parse(lines[4]); + } + } + } +} \ No newline at end of file -- cgit v1.2.3-70-g09d2