-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathScore.cpp
More file actions
52 lines (51 loc) · 1.03 KB
/
Score.cpp
File metadata and controls
52 lines (51 loc) · 1.03 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
#include "Score.h"
int Score::getScore()
{
return score;
}
void Score::setScore(int x)
{
if (x > 1)
score = (x - 1) * 100;
}
void Score::DisplayScore()
{
Renderer::draw_number(getScore(), 78, 31, 1.3, 0x0002D9);
}
void Score::readHighScore()
{
ifstream file;
string s;
file.open("Highscores.txt");
if (file.is_open()) {
int num;
for (int i = 0 ; i < 3 ; i++)
{
file >> num;
highscore[i] = num;
}
file.close();
}
}
void Score::writeHighScore()
{
if (score > highscore[2])
{
highscore[2] = score;
ofstream file;
file.open("Highscores.txt");
if (file.is_open())
{
sort(highscore.begin(),highscore.end(), greater<int>());
for (int i = 0; i < highscore.size(); i++)
{
file << highscore[i] << endl;
}
file.close();
}
}
}
void Score::DisplayHighScore()
{
Renderer::draw_number(highscore[0], 77, 10.5, 0.9, 0xE30000);
}