-
Notifications
You must be signed in to change notification settings - Fork 0
/
Score.cpp
58 lines (52 loc) · 1.13 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
#include "pch.h"
#include <Shlwapi.h>
#include <fstream>
#include "Score.h"
#include "PhatLeetLib.h"
#include "World.h"
Score::Score()
{
using namespace std::string_literals;
// Ugly Win32 bits
TCHAR szFileName[MAX_PATH];
GetModuleFileName(NULL, szFileName, MAX_PATH);
if (GetLastError())
return;
PathRemoveFileSpec(szFileName);
this->filepath = szFileName + "\\"s + filename;
Load();
}
void Score::Load()
{
std::fstream file(filepath, std::ios::in);
file >> max;
}
void Score::Save()
{
std::fstream file(filepath, std::ios::out);
file << max;
}
int Score::Add(int points)
{
if (!GetWorld().player.IsAlive())
return 0;
int added = (int)std::round(points * multiplier);
current += (int)std::round(points * multiplier);
max = std::max(max, current);
return added;
}
std::string Score::DiscoverWorld()
{
std::string name;
auto vowels = "aeiou"; // y sucks
std::normal_distribution<float> dist(5, 3);
int length = std::clamp( (int)std::round(dist(Random::generator)), 2, 10);
for (int i=0; i < length; ++i)
{
if (i % 4 == 1)
name += vowels[Random::Next(5)];
else
name += 'a' + Random::Next('z' - 'a');
}
return name;
}