-
Notifications
You must be signed in to change notification settings - Fork 0
/
rating.cpp
119 lines (97 loc) · 3.19 KB
/
rating.cpp
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include "init.h"
#include "button.h"
#include "music.h"
#include <fstream>
#pragma once
bool cmp(SortMap &a, SortMap &b){
return a.key > b.key;
}
void openLeaders(RenderWindow &window, VideoMode &mode){
Event event;
Font font;
font.loadFromFile(pathToDirectory + "fonts/font.ttf");
Text text;
text.setFont(font);
text.setCharacterSize(50);
text.setFillColor(Color(255, 120, 70, 255));
text.setPosition(100, 50);
text.setString("Top " + std::to_string(maxNumberLeaders) + " players of the game!");
text.setOutlineThickness(2);
text.setOutlineColor(Color::Red);
//records
Text text1;
text1.setFont(font);
text1.setCharacterSize(50);
text1.setFillColor(Color::Red);
text1.setPosition(100, 100);
text1.setOutlineThickness(2);
text1.setOutlineColor(Color::Black);
//names
Text text2;
text2.setFont(font);
text2.setCharacterSize(50);
text2.setFillColor(Color::Red);
text2.setPosition(1000, 100);
text2.setOutlineThickness(2);
text2.setOutlineColor(Color::Black);
std::ifstream in;
std::string string;
in.open(pathToDirectory + "leaders.txt", std::ios::in);
if(in.is_open()){
while (getline(in, string))
{
if(string != "\0"){
text1.setString(text1.getString() + "\n" + std::to_string(std::stoi(string)));
if(string.find(" ") != std::string::npos)
text2.setString(text2.getString() + "\n" + string.substr(string.find(" ") + 1, 100));
}
}
}
in.close();
Button back(mode, "BACK", pathToDirectory + "fonts/font.ttf", Color::Red);
Sprite spriteCursor(textureCursor0);
setCursor(window, spriteCursor);
Clock clock;
Time time = clock.getElapsedTime();
bool changeColor = false;
int color = 0;
while(window.isOpen()){
while(window.pollEvent(event)){
if (event.type == Event::Closed){
window.close();
}
if (event.type == event.MouseButtonReleased)
spriteCursor.setTexture(textureCursor0);
if (event.type == event.MouseButtonPressed)
spriteCursor.setTexture(textureCursor1);
if(event.type == event.MouseButtonReleased && event.mouseButton.button == Mouse::Left &&
isInsideButton(Vector2f(Mouse::getPosition(window).x, Mouse::getPosition(window).y), back.sprite)){
soundsAll.sound[9].play();
return;
}
}
time = clock.restart();
if(!changeColor){
color += (int)(time.asSeconds() * 200);
if(color > 255){
color = 255;
changeColor = true;
}
} else{
color -= (int)(time.asSeconds() * 200);
if(color < 50){
color = 50;
changeColor = false;
}
}
window.clear(Color(100, 100, color, 0));
back.update(window);
updateCursor(window, spriteCursor);
window.draw(text);
window.draw(text1);
window.draw(text2);
back.draw(window);
window.draw(spriteCursor);
window.display();
}
}