-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLeaderboard.cpp
More file actions
78 lines (73 loc) · 2.02 KB
/
Leaderboard.cpp
File metadata and controls
78 lines (73 loc) · 2.02 KB
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
73
74
75
76
77
78
#include <iostream>
#include <iomanip>
#include <fstream>
#include <algorithm>
using namespace std;
#include "Leaderboard.h"
void SaveNewScore(float time, Leaderboard& LB, int dif) {
switch(dif) {
case 1:
LB.Easy[LB.cntEasy++] = time;
sort(LB.Easy, LB.Easy + LB.cntEasy);
if (LB.cntEasy == 11)
LB.cntEasy--;
break;
case 2:
LB.Medium[LB.cntMed++] = time;
sort(LB.Medium, LB.Medium + LB.cntMed);
if (LB.cntMed == 11)
LB.cntMed--;
break;
case 3:
LB.Hard[LB.cntHard++] = time;
sort(LB.Hard, LB.Hard + LB.cntHard);
if (LB.cntHard == 11)
LB.cntHard--;
break;
}
ofstream fout;
fout.open("Leaderboard.txt");
fout << LB.cntEasy << ' ' << LB.cntMed << ' ' << LB.cntHard << endl;
for(int i = 0; i < LB.cntEasy; i++) {
fout << LB.Easy[i] << endl;
}
for(int i = 0; i < LB.cntMed; i++) {
fout << LB.Medium[i] << endl;
}
for(int i = 0; i < LB.cntHard; i++) {
fout << LB.Hard[i] << endl;
}
fout.close();
}
void LoadLeaderboard(Leaderboard& LB) {
ifstream fin;
fin.open("Leaderboard.txt");
fin >> LB.cntEasy >> LB.cntMed >> LB.cntHard;
for(int i = 0; i < LB.cntEasy; i++) {
fin >> LB.Easy[i];
}
for(int i = 0; i < LB.cntMed; i++) {
fin >> LB.Medium[i];
}
for(int i = 0; i < LB.cntHard; i++) {
fin >> LB.Hard[i];
}
fin.close();
}
void SeeLeaderboard(Leaderboard& LB) {
LoadLeaderboard(LB);
system("cls");
cout << "Easy:\n";
for(int i = 0; i < LB.cntEasy; i++) {
cout << fixed << setprecision(2) << i+1 << ". " << LB.Easy[i] << " secs.\n";
}
cout << "Medium:\n";
for(int i = 0; i < LB.cntMed; i++) {
cout << fixed << setprecision(2) << i+1 << ". " << LB.Medium[i] << " secs.\n";
}
cout << "Hard:\n";
for(int i = 0; i < LB.cntHard; i++) {
cout << fixed << setprecision(2) << i+1 << ". " << LB.Hard[i] << " secs.\n";
}
system("pause");
}