forked from 2goodAP/QuizmaHeros102
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HighScore.cpp
124 lines (95 loc) · 3.04 KB
/
HighScore.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
120
121
122
123
124
#pragma once
#include <sstream>
#include "DEFINITIONS.hpp"
#include "MainMenuState.hpp"
#include "HighScore.hpp"
#include "GameOverState.hpp"
#include <iostream>
namespace Quizma
{
HighScore::HighScore(GameDataRef data) : _data(data)
{
}
void HighScore::Init()
{
this->_data->window.setMouseCursorVisible(false);
_name_file.open(PLAYER_RECORD_FILEPATH);
_font.loadFromFile(PLAYER_FONT_FILEPATH);
_text.setFont(_font);
_text.setCharacterSize(50);
_text.setFillColor(sf::Color::Black);
this->_data->assets.LoadTexture("High Score Background", HIGH_SCORE_FILEPATH);
this->_data->assets.LoadTexture("Back", BACK_BUTTON_FILEPATH);
this->_data->assets.LoadTexture("Cursor", CURSOR_FILEPATH);
_background.setTexture(this->_data->assets.GetTexture("High Score Background"));
_backButton.setTexture(this->_data->assets.GetTexture("Back"));
_cursor.setTexture(this->_data->assets.GetTexture("Cursor"));
_cursor.setScale(0.35, 0.35);
_cursor.setPosition((SCREEN_WIDTH / 2) - (_cursor.getGlobalBounds().width / 2), (SCREEN_HEIGHT / 2) - (_cursor.getGlobalBounds().height / 2));
_backButton.setPosition(1300, 950);
positionText.x = 650;
positionText.y = 450;
if (_name_file.is_open())
{
result_no = 0;
std::string line;
while (std::getline(_name_file, line)) {
std::cout << this->_data->highscoreCat[11] << line[18];
if ((line[18]) == this->_data->highscoreCat[11]) {
result.push_back(line);
result_no++;
}
}
_name_file.close();
}
std::sort(result.begin(), result.end());
for (std::vector<std::string>::iterator it = result.begin(); it != result.end(); ++it) {
std::cout << ' ' << *it;
std::cout << '\n';
}
}
void HighScore::HandleInput()
{
sf::Event event;
while (this->_data->window.pollEvent(event))
{
if (sf::Event::Closed == event.type)
{
this->_data->window.close();
}
if (sf::Event::KeyPressed)
{
if (event.key.code == sf::Keyboard::Escape)
{
this->_data->machine.AddState(StateRef(new MainMenuState(_data)), true);
}
}
if (this->_data->input.IsSpriteClicked(this->_backButton, sf::Mouse::Left, this->_data->window))
{
this->_data->sound.setBuffer(this->_data->buffer);
this->_data->sound.play();
this->_data->machine.AddState(StateRef(new MainMenuState(_data)), true);
}
_cursor.setPosition(static_cast<sf::Vector2f>(sf::Mouse::getPosition(this->_data->window)));
}
}
void HighScore::Update(float dt)
{
}
void HighScore::Draw(float dt)
{
this->_data->window.clear(sf::Color::Black);
this->_data->window.draw(this->_background);
this->_data->window.draw(this->_backButton);
positionText.y = 450;
for (int i = 0; i < result_no; i++)
{
_text.setPosition(positionText.x,positionText.y);
_text.setString(result[i]);
this->_data->window.draw(_text);
positionText.y += 55;
}
this->_data->window.draw(this->_cursor);
this->_data->window.display();
}
}