-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgressService.cs
More file actions
92 lines (82 loc) · 2.74 KB
/
ProgressService.cs
File metadata and controls
92 lines (82 loc) · 2.74 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
namespace Sainauna;
public static class ProgressService
{
private static int _totalPoints = 0;
private static int _maxPoints = 1000;
private static int _bestMemorizeScore = 0;
private static int _bestQuizScore = 0;
private static int _bestTestScore = 0;
private static int _bestWriteScore = 0;
private static int _totalWriteSpeedPoints = 0;
private static int _totalWriteAccuracyPoints = 0;
private static int _writeSessionsCompleted = 0;
public static event Action? ProgressChanged;
public static int TotalPoints => _totalPoints;
public static int MaxPoints => _maxPoints;
public static double ProgressPercentage => (_totalPoints / (double)_maxPoints) * 100;
public static int BestMemorizeScore => _bestMemorizeScore;
public static int BestQuizScore => _bestQuizScore;
public static int BestTestScore => _bestTestScore;
public static int BestWriteScore => _bestWriteScore;
public static void UpdateMemorizeScore(int newScore)
{
if (newScore > _bestMemorizeScore)
{
_totalPoints -= _bestMemorizeScore;
_bestMemorizeScore = newScore;
_totalPoints += _bestMemorizeScore;
ProgressChanged?.Invoke();
}
}
public static void UpdateQuizScore(int newScore)
{
if (newScore > _bestQuizScore)
{
_totalPoints -= _bestQuizScore;
_bestQuizScore = newScore;
_totalPoints += _bestQuizScore;
ProgressChanged?.Invoke();
}
}
public static void UpdateTestScore(int newScore)
{
if (newScore > _bestTestScore)
{
_totalPoints -= _bestTestScore;
_bestTestScore = newScore;
_totalPoints += _bestTestScore;
ProgressChanged?.Invoke();
}
}
public static void UpdateWriteScore(int totalPoints)
{
int speedPortion = totalPoints / 2;
int accuracyPortion = totalPoints - speedPortion;
_totalWriteSpeedPoints += speedPortion;
_totalWriteAccuracyPoints += accuracyPortion;
_writeSessionsCompleted++;
if (totalPoints > _bestWriteScore)
{
_totalPoints -= _bestWriteScore;
_bestWriteScore = totalPoints;
_totalPoints += _bestWriteScore;
ProgressChanged?.Invoke();
}
else
{
ProgressChanged?.Invoke();
}
}
public static void ResetProgress()
{
_totalPoints = 0;
_bestMemorizeScore = 0;
_bestQuizScore = 0;
_bestTestScore = 0;
_bestWriteScore = 0;
_totalWriteSpeedPoints = 0;
_totalWriteAccuracyPoints = 0;
_writeSessionsCompleted = 0;
ProgressChanged?.Invoke();
}
}