-
Notifications
You must be signed in to change notification settings - Fork 0
/
Score.cpp
61 lines (48 loc) · 1.38 KB
/
Score.cpp
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
#include "Score.h"
void Score::addPoints(const int points) noexcept
{
this->score += points;
}
int Score::getScore() const noexcept
{
return this->score;
}
void Score::setScore(const int score) noexcept
{
this->score = score;
}
void Score::saveScore(const int score)
{
LPCSTR reg_path = "SOFTWARE\\SpaceInvaders";
HKEY default_key;
auto status = RegCreateKeyExA(HKEY_CURRENT_USER, reg_path, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &default_key, NULL);
if (status == ERROR_SUCCESS)
{
// Writing
DWORD value = score;
status = RegSetValueExA(default_key, "score", 0, REG_DWORD, (const BYTE*)&value, sizeof(value));
}
RegCloseKey(default_key);
}
int Score::getTopScore()
{
DWORD data = 0;
LPCSTR reg_path = "SOFTWARE\\SpaceInvaders";
HKEY default_key;
auto status = RegCreateKeyExA(HKEY_CURRENT_USER, reg_path, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &default_key, NULL);
if (status == ERROR_SUCCESS)
{
// Reading
DWORD size = sizeof(DWORD);
DWORD type = REG_DWORD;
status = RegQueryValueExA(default_key, "score", NULL, &type, (LPBYTE)&data, &size);
}
RegCloseKey(default_key);
return data;
}
void Score::tick(const Time time)
{
this->textScore = std::to_string(this->score);
text.setText(this->textScore);
text.tick(time);
}