109 lines
1.6 KiB
C++
109 lines
1.6 KiB
C++
#include "scorestate.hpp"
|
|
|
|
|
|
bool operator< (ScoreItem First, ScoreItem Second )
|
|
{
|
|
return (First.GetLines() > Second.GetLines());
|
|
}
|
|
|
|
|
|
ScoreState ScoreState::m_ScoreState;
|
|
|
|
void ScoreState::Draw ( game * Game )
|
|
{
|
|
for (int i = 0; i < (Items.size() > 10 ? 10 : (int) Items.size()); i++)
|
|
{
|
|
Items[i].Draw(Game, i * 35);
|
|
}
|
|
|
|
SDL_Flip(Game->GetScreen());
|
|
}
|
|
|
|
void ScoreState::Update ( game * Game )
|
|
{
|
|
SDL_FillRect(Game->GetScreen(), NULL, 0x000000);
|
|
}
|
|
|
|
void ScoreState::HandleEvents ( game * Game )
|
|
{
|
|
SDL_Event event;
|
|
|
|
while (SDL_PollEvent(&event))
|
|
{
|
|
switch (event.type)
|
|
{
|
|
case SDL_QUIT:
|
|
Game->Quit();
|
|
break;
|
|
|
|
case SDL_KEYDOWN:
|
|
switch (event.key.keysym.sym)
|
|
{
|
|
case SDLK_ESCAPE:
|
|
Game->PopState();
|
|
break;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
void ScoreState::Resume()
|
|
{
|
|
# ifdef DEBUG
|
|
std::cout << "ScoreState Resumed" << std::endl;
|
|
# endif
|
|
}
|
|
|
|
void ScoreState::Pause()
|
|
{
|
|
# ifdef DEBUG
|
|
std::cout << "ScoreState Paused" << std::endl;
|
|
# endif
|
|
}
|
|
|
|
void ScoreState::Clean()
|
|
{
|
|
Items.clear();
|
|
|
|
# ifdef DEBUG
|
|
std::cout << "ScoreState Clean Successful" << std::endl;
|
|
# endif
|
|
}
|
|
|
|
void ScoreState::Init()
|
|
{
|
|
Load();
|
|
|
|
sort(Items.begin(), Items.end());
|
|
|
|
# ifdef DEBUG
|
|
std::cout << "ScoreState Init Successful" << std::endl;
|
|
# endif
|
|
}
|
|
|
|
void ScoreState::Load()
|
|
{
|
|
ifstream file;
|
|
string Name;
|
|
int Lines;
|
|
|
|
file.open(".score");
|
|
|
|
if (file.is_open())
|
|
{
|
|
while (!file.eof())
|
|
{
|
|
file >> Name;
|
|
file >> Lines;
|
|
|
|
if (!file.eof())
|
|
Items.push_back(ScoreItem(Name, Lines));
|
|
}
|
|
|
|
file.close();
|
|
}
|
|
else
|
|
cerr << "Cannot open file '.score'" << endl;
|
|
}
|