-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhighscore.hpp
72 lines (61 loc) · 1.28 KB
/
highscore.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
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
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <string>
using namespace std;
bool update_highscore(int points) {
ofstream filew;
ifstream filer;
int hspoints;
bool newfile = false;
filer.open("./highscores", ios::out);
bool hs = false; //This variable represents if the given points results in a new highscore or not
if (!filer.is_open()) {
filew.open("./highscores");
filew << "0";
hspoints = 0;
newfile = true;
filew.close();
}
if (!newfile) {
string output = "";
string line;
while (std::getline(filer, line)) {
hspoints = stoi(line);
}
}
filer.close();
if (hspoints > points) {
hs = false;
} else {
filew.open("./highscores");
string newpoints = to_string(points);
filew << newpoints;
filew.close();
hs = true;
}
return hs;
}
int get_highscore() {
ofstream filew;
ifstream filer;
int hspoints;
bool newfile = false;
filer.open("./highscores", ios::out);
if (!filer.is_open()) {
filew.open("./highscores");
filew << "0";
hspoints = 0;
newfile = true;
filew.close();
}
if (!newfile) {
string output = "";
string line;
while (std::getline(filer, line)) {
hspoints = stoi(line);
}
}
filer.close();
return hspoints;
}