afegit separador de milers a la tabla de puntuacions
This commit is contained in:
@@ -452,6 +452,9 @@ void Director::initOptions()
|
||||
// Opciones de juego
|
||||
options->game.difficulty = DIFFICULTY_NORMAL;
|
||||
options->game.language = ba_BA;
|
||||
ManageHiScoreTable *m = new ManageHiScoreTable(&options->game.hiScoreTable);
|
||||
m->clear();
|
||||
delete m;
|
||||
|
||||
// Opciones de control
|
||||
options->controller.clear();
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "player.h"
|
||||
#include "title.h"
|
||||
#include "load_param.h"
|
||||
#include "manage_hiscore_table.h"
|
||||
|
||||
#ifndef DIRECTOR_H
|
||||
#define DIRECTOR_H
|
||||
|
||||
@@ -65,6 +65,14 @@ Game::~Game()
|
||||
saveDemoFile();
|
||||
#endif
|
||||
|
||||
if (!demo.enabled)
|
||||
{
|
||||
hiScoreEntry_t entry = {"Sergio", players[0]->getScore()};
|
||||
ManageHiScoreTable *m = new ManageHiScoreTable(&options->game.hiScoreTable);
|
||||
m->add(entry);
|
||||
delete m;
|
||||
}
|
||||
|
||||
// Elimina todos los objetos contenidos en vectores
|
||||
deleteAllVectorObjects();
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "scoreboard.h"
|
||||
#include "background.h"
|
||||
#include "lang.h"
|
||||
#include "manage_hiscore_table.h"
|
||||
#include <iostream>
|
||||
|
||||
#ifndef GAME_H
|
||||
@@ -174,8 +175,8 @@ private:
|
||||
|
||||
// Variables
|
||||
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
||||
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||
Uint32 hiScore; // Puntuación máxima
|
||||
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||
int hiScore; // Puntuación máxima
|
||||
bool hiScoreAchieved; // Indica si se ha superado la puntuación máxima
|
||||
std::string hiScoreName; // Nombre del jugador que ostenta la máxima puntuación
|
||||
stage_t stage[10]; // Variable con los datos de cada pantalla
|
||||
@@ -188,8 +189,8 @@ private:
|
||||
int menaceThreshold; // Umbral del nivel de amenaza. Si el nivel de amenaza cae por debajo del umbral, se generan más globos. Si el umbral aumenta, aumenta el número de globos
|
||||
bool timeStopped; // Indica si el tiempo está detenido
|
||||
int timeStoppedCounter; // Temporizador para llevar la cuenta del tiempo detenido
|
||||
Uint32 counter; // Contador para el juego
|
||||
Uint32 scoreDataFile[TOTAL_SCORE_DATA]; // Datos del fichero de puntos
|
||||
int counter; // Contador para el juego
|
||||
int scoreDataFile[TOTAL_SCORE_DATA]; // Datos del fichero de puntos
|
||||
int balloonsPopped; // Lleva la cuenta de los globos explotados
|
||||
int lastEnemyDeploy; // Guarda cual ha sido la última formación desplegada para no repetir;
|
||||
int enemyDeployCounter; // Cuando se lanza una formación, se le da un valor y no sale otra hasta que llegue a cero
|
||||
|
||||
@@ -108,20 +108,19 @@ void HiScoreTable::fillTexture()
|
||||
// Escribe el texto: Mejores puntuaciones
|
||||
text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, GAMECANVAS_CENTER_X, firstLine, lang->getText(42), 1, orangeColor, 1, shdwTxtColor);
|
||||
|
||||
// Rellena la lista con nombres
|
||||
std::vector<std::string> names;
|
||||
names.insert(names.end(), {"Bry", "Usufondo", "G.Lucas", "P.Delgat", "P.Arrabalera", "Pelechano", "Sahuquillo", "Bacteriol", "Pepe", "Rosita"});
|
||||
|
||||
// Escribe los nombres de la tabla de puntuaciones
|
||||
for (int i = 0; i < maxNames; ++i)
|
||||
{
|
||||
const int nameLenght = names[i].length();
|
||||
const int numDots = 20 - nameLenght;
|
||||
const int nameLenght = options->game.hiScoreTable[i].name.length();
|
||||
const std::string score = format(options->game.hiScoreTable[i].score);
|
||||
const int scoreLenght = score.size();
|
||||
const int numDots = 25 - nameLenght - scoreLenght;
|
||||
std::string dots = "";
|
||||
for (int j = 0; j < numDots; ++j)
|
||||
{
|
||||
dots = dots + ".";
|
||||
}
|
||||
const std::string line = names[i] + dots + "0000000";
|
||||
const std::string line = options->game.hiScoreTable[i].name + dots + score;
|
||||
text->writeDX(TXT_CENTER | TXT_SHADOW, GAMECANVAS_CENTER_X, (i * spaceBetweenLines) + firstLine + spaceBetweenHeader, line, 1, orangeColor, 1, shdwTxtColor);
|
||||
}
|
||||
|
||||
@@ -216,7 +215,7 @@ void HiScoreTable::run()
|
||||
}
|
||||
|
||||
// Transforma un valor numérico en una cadena de 6 cifras
|
||||
std::string HiScoreTable::scoreToString(Uint32 num)
|
||||
std::string HiScoreTable::scoreToString(int num)
|
||||
{
|
||||
if ((num >= 0) && (num <= 9))
|
||||
{
|
||||
@@ -272,4 +271,44 @@ void HiScoreTable::updateFade()
|
||||
{
|
||||
section->name = SECTION_PROG_INSTRUCTIONS;
|
||||
}
|
||||
}
|
||||
|
||||
// Convierte un entero a un string con separadores de miles
|
||||
std::string HiScoreTable::format(int number)
|
||||
{
|
||||
const std::string separator = ".";
|
||||
|
||||
if (number < 1000)
|
||||
{
|
||||
return std::to_string(number);
|
||||
}
|
||||
|
||||
else if (number >= 1000 && number < 1000000)
|
||||
{
|
||||
const std::string num1 = std::to_string(number / 1000);
|
||||
const std::string num2 = std::to_string(number % 1000);
|
||||
return num1 + separator + fillZeros(num2);
|
||||
}
|
||||
|
||||
else if (number >= 1000000)
|
||||
{
|
||||
const std::string num1 = std::to_string(number / 1000000);
|
||||
const std::string num2 = std::to_string(number % 1000000 / 1000);
|
||||
const std::string num3 = std::to_string(number % 1000000 % 1000);
|
||||
return num1 + separator + fillZeros(num2) + separator + fillZeros(num3);
|
||||
}
|
||||
|
||||
return std::to_string(number);
|
||||
}
|
||||
|
||||
// Añade ceros a una cadena
|
||||
std::string HiScoreTable::fillZeros(std::string text, int size)
|
||||
{
|
||||
std::string result = text;
|
||||
for (int i=(int)text.size(); i < size; ++i)
|
||||
{
|
||||
result = '0' + result;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -55,8 +55,14 @@ private:
|
||||
// Comprueba las entradas
|
||||
void checkInput();
|
||||
|
||||
// Convierte un entero a un string con separadores de miles
|
||||
std::string format(int number);
|
||||
|
||||
// Añade ceros a una cadena
|
||||
std::string fillZeros(std::string text, int size = 3);
|
||||
|
||||
// Transforma un valor numérico en una cadena de 6 cifras
|
||||
std::string scoreToString(Uint32 num);
|
||||
std::string scoreToString(int num);
|
||||
|
||||
// Crea el contenido de la textura con la lista de puntuaciones
|
||||
void fillTexture();
|
||||
|
||||
@@ -51,7 +51,7 @@ void ManageHiScoreTable::sort()
|
||||
{
|
||||
struct
|
||||
{
|
||||
bool operator()(hiScoreEntry_t a, hiScoreEntry_t b) const { return a.score < b.score; }
|
||||
bool operator()(hiScoreEntry_t a, hiScoreEntry_t b) const { return a.score > b.score; }
|
||||
} customLess;
|
||||
|
||||
std::sort(table->begin(), table->end(), customLess);
|
||||
|
||||
@@ -342,7 +342,7 @@ void Player::update()
|
||||
}
|
||||
|
||||
// Obtiene la puntuación del jugador
|
||||
Uint32 Player::getScore()
|
||||
int Player::getScore()
|
||||
{
|
||||
return score;
|
||||
}
|
||||
@@ -438,13 +438,13 @@ void Player::setInvulnerable(bool value)
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
Uint16 Player::getInvulnerableCounter()
|
||||
int Player::getInvulnerableCounter()
|
||||
{
|
||||
return invulnerableCounter;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Player::setInvulnerableCounter(Uint16 value)
|
||||
void Player::setInvulnerableCounter(int value)
|
||||
{
|
||||
invulnerableCounter = value;
|
||||
}
|
||||
@@ -480,13 +480,13 @@ void Player::setPowerUp()
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
Uint16 Player::getPowerUpCounter()
|
||||
int Player::getPowerUpCounter()
|
||||
{
|
||||
return powerUpCounter;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Player::setPowerUpCounter(Uint16 value)
|
||||
void Player::setPowerUpCounter(int value)
|
||||
{
|
||||
powerUpCounter = value;
|
||||
}
|
||||
|
||||
@@ -52,18 +52,18 @@ private:
|
||||
float baseSpeed; // Velocidad base del jugador
|
||||
int cooldown; // Contador durante el cual no puede disparar
|
||||
|
||||
Uint32 score; // Puntos del jugador
|
||||
int score; // Puntos del jugador
|
||||
float scoreMultiplier; // Multiplicador de puntos
|
||||
|
||||
int statusWalking; // Estado del jugador
|
||||
int statusFiring; // Estado del jugador
|
||||
|
||||
bool invulnerable; // Indica si el jugador es invulnerable
|
||||
Uint16 invulnerableCounter; // Contador para la invulnerabilidad
|
||||
int invulnerableCounter; // Contador para la invulnerabilidad
|
||||
bool extraHit; // Indica si el jugador tiene un toque extra
|
||||
int coffees; // Indica cuantos cafes lleva acumulados
|
||||
bool powerUp; // Indica si el jugador tiene activo el modo PowerUp
|
||||
Uint16 powerUpCounter; // Temporizador para el modo PowerUp
|
||||
int powerUpCounter; // Temporizador para el modo PowerUp
|
||||
bool input; // Indica si puede recibir ordenes de entrada
|
||||
circle_t collider; // Circulo de colisión del jugador
|
||||
bool alive; // Indica si el jugador está vivo
|
||||
@@ -134,7 +134,7 @@ public:
|
||||
void updateCooldown();
|
||||
|
||||
// Obtiene la puntuación del jugador
|
||||
Uint32 getScore();
|
||||
int getScore();
|
||||
|
||||
// Asigna un valor a la puntuación del jugador
|
||||
void setScore(Uint32 score);
|
||||
@@ -167,10 +167,10 @@ public:
|
||||
void setInvulnerable(bool value);
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
Uint16 getInvulnerableCounter();
|
||||
int getInvulnerableCounter();
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setInvulnerableCounter(Uint16 value);
|
||||
void setInvulnerableCounter(int value);
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
bool isPowerUp();
|
||||
@@ -179,10 +179,10 @@ public:
|
||||
void setPowerUp();
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
Uint16 getPowerUpCounter();
|
||||
int getPowerUpCounter();
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setPowerUpCounter(Uint16 value);
|
||||
void setPowerUpCounter(int value);
|
||||
|
||||
// Actualiza el valor de la variable
|
||||
void updatePowerUpCounter();
|
||||
|
||||
Reference in New Issue
Block a user