From ff4b21d06d6272b80380fddca659418469023d50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Valor=20Mart=C3=ADnez?= Date: Sun, 14 Jul 2024 22:13:11 +0200 Subject: [PATCH] =?UTF-8?q?millorada=20la=20funci=C3=B3=20de=20posar=20sep?= =?UTF-8?q?aradors=20de=20milers?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/hiscore_table.cpp | 42 +++++++++++++--------------------------- source/hiscore_table.h | 3 --- 2 files changed, 13 insertions(+), 32 deletions(-) diff --git a/source/hiscore_table.cpp b/source/hiscore_table.cpp index a03f491..7c6efb9 100644 --- a/source/hiscore_table.cpp +++ b/source/hiscore_table.cpp @@ -277,37 +277,21 @@ void HiScoreTable::updateFade() std::string HiScoreTable::format(int number) { const std::string separator = "."; - - if (number < 1000) - { - return std::to_string(number); - } + const std::string score = std::to_string(number); - else if (number >= 1000 && number < 1000000) + int index = (int)score.size() - 1; + std::string result = ""; + int i = 0; + while (index >= 0) { - 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; + result = score.at(index) + result; + index--; + i++; + if (i == 3) + { + i = 0; + result = separator + result; + } } return result; diff --git a/source/hiscore_table.h b/source/hiscore_table.h index 9c710e9..8b90454 100644 --- a/source/hiscore_table.h +++ b/source/hiscore_table.h @@ -58,9 +58,6 @@ private: // 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(int num);