Repository navigation
Expand file tree
/
Copy pathgameover.cpp
More file actions
85 lines (70 loc) · 2.09 KB
/
Copy pathgameover.cpp
File metadata and controls
85 lines (70 loc) · 2.09 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
79
80
81
82
83
84
85
#include "gameover.h"
using namespace std;
using namespace sf;
gameover::gameover()
{
gameovertext.loadFromFile("images/gameover.png");
fondgameover.setTexture(gameovertext);
bouton.loadFromFile("images/StartIcon.png");
SpriteBouton.setTexture(bouton);
SpriteBouton.setPosition(260,290);
font.loadFromFile("arial.ttf");
text1.setFont(font);
text1.setCharacterSize(24);
text1.setStyle(sf::Text::Regular);
text1.setPosition(50,80);
text2.setFont(font);
text2.setCharacterSize(24);
text2.setStyle(sf::Text::Regular);
text2.setPosition(50,110);
}
bool gameover::lancement(sf::RenderWindow *renderWindow,string scorefinal,int hauteur)
{
scorefinal = "Votre score : " + scorefinal;
text1.setString(scorefinal);
renderWindow->draw(fondgameover);
renderWindow->draw(SpriteBouton);
renderWindow->draw(text1);
writescore(hauteur);
renderWindow->draw(text2);
position_mouse = sf::Mouse::getPosition(*renderWindow);
if ((SpriteBouton.getGlobalBounds().contains(position_mouse.x,position_mouse.y)) && (sf::Mouse::isButtonPressed(sf::Mouse::Left)))
{
return true;
}
}
void gameover::writescore(int hauteur)
{
ifstream out_scoring("images/scores.txt");
if(out_scoring)
{
string contenu;
getline(out_scoring, contenu);
text2.setString(meilleurscore);
out_scoring.close();
stringstream ss;
int f;
ss.str(contenu);
ss >> f;
stringstream convert;
convert << hauteur;
if (f < hauteur)
{
ofstream in_scoring("images/scores.txt");
in_scoring << hauteur;
in_scoring.close();
meilleurscore = "Nouveau meilleur score ! : " + convert.str() + "km";
text2.setColor(sf::Color::Yellow);
}
else if (f > hauteur)
{
text2.setColor(sf::Color::White);
meilleurscore = "Meilleur score : " + contenu + "km";
}
}
else
{
cout << "ERREUR: Impossible d'ouvrir le fichier." << endl;
}
}
gameover::~gameover() {}