-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.xaml.cs
More file actions
76 lines (66 loc) · 2.05 KB
/
App.xaml.cs
File metadata and controls
76 lines (66 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Text.Json;
using System.Reflection.Emit;
using System.Windows.Controls;
using System.Runtime.InteropServices;
namespace MathMastermind
{
/// <summary>
/// Logika interakcji dla klasy App.xaml
/// </summary>
///
public class User {
public static string FilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "MathMastermind\\UserData.json");
public int XP_Points { get; set; }
public int ELO_Easy { get; set; }
public int ELO_Medium { get; set; }
public int ELO_Hard { get; set; }
public int Correct_Answers { get; set; }
public int Wrong_Answers { get; set; }
public User()
{
var dirPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "MathMastermind");
if (!Directory.Exists(dirPath))
{
Directory.CreateDirectory(dirPath);
}
if (!File.Exists(FilePath))
{
XP_Points = 0;
ELO_Easy = 0;
ELO_Medium = 0;
ELO_Hard = 0;
Correct_Answers = 0;
Wrong_Answers = 0;
SaveToFile(this);
}
}
public static void SaveToFile(User user)
{
string fileName = FilePath;
string jsonString = JsonSerializer.Serialize(user);
File.WriteAllText(fileName, jsonString);
}
public static User LoadFromFile()
{
string fileName = FilePath;
string jsonString = File.ReadAllText(fileName);
User user = JsonSerializer.Deserialize<User>(jsonString);
return user;
}
}
public partial class App : Application
{
static App()
{
User user = new User();
}
}
}