-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhighscore.cpp
More file actions
executable file
·45 lines (38 loc) · 941 Bytes
/
Copy pathhighscore.cpp
File metadata and controls
executable file
·45 lines (38 loc) · 941 Bytes
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
#include "highscore.hpp"
vector<pair<int, string>> scoreVector;
void Score::reCalculate()
{
sort(scoreVector.begin(), scoreVector.end(), greater<pair<int, string>>());
fstream scorefile;
scorefile.open("highscore.txt", ios::out );
for (auto &it : scoreVector)
{
scorefile << it.first << ' ' << it.second << endl;
}
scorefile.close();
}
void Score::addScore(int score, const string &name)
{
scoreVector.push_back({score, name});
reCalculate();
}
void Score::inputScore()
{
int score;
string name;
ifstream scorefile;
scorefile.open("highscore.txt");
while (scorefile >> score >> name)
{
scoreVector.push_back({score, name});
}
scorefile.close();
}
vector<pair<int, string>> Score::topFive(){
vector<pair<int, string>> v;
for (int i = 0; i < min((int)scoreVector.size(), 5); i++)
{
v.push_back(scoreVector[i]);
}
return v;
}