<commit_before>/*
 * NicoW
 * 31.05.12
 */

#include <iostream>		// REMOVE
#include <algorithm>
#include <sstream>
#include <vector>
#include "Match.hpp"
#include "GameResult.hpp"
#include "GameManager.hpp"

GameResult::GameResult(GameManager & game, Match & match)
  : AMenu("menu/background/backgroundResult.jpg", "menu/background/backgroundResult.jpg", 4800.0f, -1.0f, 0.0f, game),
    _isBuilt(false),
    _match(match)
{
  this->_tags.push_back(new Tag("menu/tags/BackSmallNormal.png", "menu/tags/BackSmallHighlit.png", true, false, TokenMenu::GAMERESULT, 5950.0f, 0.0f, 700.0f));
}

GameResult::~GameResult(void)
{
}

double		GameResult::getCenterX() const
{
  return 5600.0f;
}

double		GameResult::getCenterY() const
{
  return 400.0f;
}

static bool		orderKill(APlayer *one, APlayer *two)
{
  return (one && two && one->getNbKills() > two->getNbKills());
}

void		GameResult::buildPlayerScore()
{
  this->_playerScore = this->_match._players;
  for (std::list<APlayer*>::iterator deadIt = this->_match._dead.begin() ; deadIt != this->_match._dead.end() ; ++deadIt)
    this->_playerScore.push_back(*deadIt);
  for (std::list<APlayer*>::iterator cadaverIt = this->_match._cadaver.begin() ; cadaverIt != this->_match._cadaver.end() ; ++cadaverIt)
    this->_playerScore.push_back(*cadaverIt);
}

void		GameResult::buildGameResult()
{
  this->buildPlayerScore();
  std::sort(_playerScore.begin(), _playerScore.end(), orderKill);
  this->_isBuilt = true;
}

void		GameResult::update(gdl::GameClock const& clock, gdl::Input& input)
{
  if (this->_isBuilt)
    {
      for (size_t i = 0; i < this->_keyEvent.size(); ++i)
	if (input.isKeyDown(this->_keyEvent[i].first))
	  (this->*_keyEvent[i].second)(clock);
      if (this->_curToken == TokenMenu::GAMERESULT)
	this->_isBuilt = false;
    }
  else
    this->buildGameResult();
}

void		GameResult::draw()
{
  int	y = 358;

  AMenu::draw();

  for (unsigned int i = 0 ; this->_textDraw == true && i < this->_playerScore.size() && i < 5; ++i)
    {
      int		x = 400;
      gdl::Text		text;
      std::string	str;
      std::stringstream	sstrm;
      APlayer*		playerScore = this->_playerScore[i];<commit_msg>Maj GameResult<commit_after>/*
 * NicoW
 * 31.05.12
 */

#include <iostream>		// REMOVE
#include <algorithm>
#include <sstream>
#include <vector>
#include "Match.hpp"
#include "GameResult.hpp"
#include "GameManager.hpp"

GameResult::GameResult(GameManager & game, Match & match)
  : AMenu("menu/background/backgroundResult.jpg", "menu/background/backgroundResult.jpg", 4800.0f, -1.0f, 0.0f, game),
    _isBuilt(false),
    _match(match)
{
  this->_tags.push_back(new Tag("menu/tags/BackSmallNormal.png", "menu/tags/BackSmallHighlit.png", true, false, TokenMenu::GAMERESULT, 5950.0f, 0.0f, 700.0f));
}

GameResult::~GameResult(void)
{
}

double		GameResult::getCenterX() const
{
  return 5600.0f;
}

double		GameResult::getCenterY() const
{
  return 400.0f;
}

static bool		orderKill(APlayer *one, APlayer *two)
{
  return (one && two && one->getNbKills() > two->getNbKills());
}

void		GameResult::buildPlayerScore()
{
  this->_playerScore = this->_match._players;
  for (std::list<APlayer*>::iterator deadIt = this->_match._dead.begin() ; deadIt != this->_match._dead.end() ; ++deadIt)
    this->_playerScore.push_back(*deadIt);
  for (std::list<APlayer*>::iterator cadaverIt = this->_match._cadaver.begin() ; cadaverIt != this->_match._cadaver.end() ; ++cadaverIt)
    this->_playerScore.push_back(*cadaverIt);
}

void		GameResult::buildGameResult()
{
  this->buildPlayerScore();
  std::sort(_playerScore.begin(), _playerScore.end(), orderKill);
  this->_isBuilt = true;
}

void		GameResult::update(gdl::GameClock const& clock, gdl::Input& input)
{
  if (this->_isBuilt)
    {
      for (size_t i = 0; i < this->_keyEvent.size(); ++i)
	if (input.isKeyDown(this->_keyEvent[i].first))
	  (this->*_keyEvent[i].second)(clock);
      if (this->_curToken == TokenMenu::GAMERESULT)
	this->_isBuilt = false;
    }
  else
    this->buildGameResult();
}

void		GameResult::draw()
{
  int		y = 358;
  gdl::Text	text;

  AMenu::draw();

  if (this->_textDraw == true)
    {
      text.setText("Bite");
      text.setSize(20);
      text.setPosition(810, 190);
      text.draw();
    }
  for (unsigned int i = 0 ; this->_textDraw == true && i < this->_playerScore.size() && i < 5; ++i)
    {
      int		x = 400;
      std::string	str;
      std::stringstream	sstrm;
      APlayer*		playerScore = this->_playerScore[i];
{'fraction_non_alphanumeric': 0.177892145893936, 'fraction_numerical': 0.0214813157305885, 'mean_word_length': 4.1976744186046515, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 64, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3555574', 'n_tokens_mistral': 1734, 'n_tokens_neox': 1655, 'n_words': 296}