-
Notifications
You must be signed in to change notification settings - Fork 0
/
levelup.hpp
43 lines (37 loc) · 968 Bytes
/
levelup.hpp
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
#pragma once
#include <cstdint>
#include "types.hpp"
class LevelSystem {
public:
LevelSystem() {
CurrentLevel = static_cast<leveltype>(1u);
CurrentEXP = static_cast<leveltype>(0u);
EXPToNextLevel = LEVEL2AT;
}
void gainExp(exptype exp) {
CurrentEXP += exp;
while (check_if_leveled()) {
};
}
virtual void LevelUp() = 0;
auto getLevel() -> leveltype { return CurrentLevel; }
auto getCurrentEXP() -> exptype { return CurrentEXP; }
auto getEXPToNextLevel() -> exptype { return EXPToNextLevel; }
private:
static const exptype LEVEL2AT = 100u;
protected:
leveltype CurrentLevel = 1u;
leveltype CurrentEXP = 1u;
exptype EXPToNextLevel;
leveltype LevelUpsAvailable = 0u;
auto check_if_leveled() -> bool {
static const leveltype LEVELSCALAR = 2u;
if (CurrentEXP >= EXPToNextLevel) {
CurrentLevel++;
LevelUp();
EXPToNextLevel *= LEVELSCALAR;
return true;
}
return false;
}
};