Redissenyat el time stopper

This commit is contained in:
2024-10-27 13:36:00 +01:00
parent ddfb3672ea
commit 71f76fda05
12 changed files with 233 additions and 398 deletions

View File

@@ -16,7 +16,7 @@ void EnterName::init()
// Inicia la lista de caracteres permitidos
character_list_ = " ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-+-*/=?¿<>!\"#$%&/()";
position_ = 0;
num_characters_ = (int)character_list_.size();
num_characters_ = static_cast<int>(character_list_.size());
// Pone la lista de indices para que refleje el nombre
updateCharacterIndex();
@@ -36,7 +36,7 @@ void EnterName::incPosition()
// Decrementa la posición
void EnterName::decPosition()
{
position_--;
--position_;
position_ = std::max(position_, 0);
}
@@ -76,14 +76,14 @@ void EnterName::updateName()
void EnterName::updateCharacterIndex()
{
// Rellena de espacios y marca como no usados
for (int i = 0; i < NAME_LENGHT; ++i)
for (size_t i = 0; i < NAME_LENGHT; ++i)
{
character_index_[i] = 0;
position_has_been_used_[i] = false;
}
// Coloca los índices en funcion de los caracteres que forman el nombre
for (int i = 0; i < (int)name_.size(); ++i)
// Coloca los índices en función de los caracteres que forman el nombre
for (size_t i = 0; i < name_.size(); ++i)
{
character_index_[i] = findIndex(name_.at(i));
position_has_been_used_[i] = true;
@@ -91,15 +91,11 @@ void EnterName::updateCharacterIndex()
}
// Encuentra el indice de un caracter en "character_list_"
int EnterName::findIndex(char character)
int EnterName::findIndex(char character) const
{
for (int i = 0; i < (int)character_list_.size(); ++i)
{
if (character == character_list_[i])
{
for (size_t i = 0; i < character_list_.size(); ++i)
if (character == character_list_.at(i))
return i;
}
}
return 0;
}
@@ -121,9 +117,7 @@ void EnterName::checkIfPositionHasBeenUsed()
auto used = position_has_been_used_[position_];
if (!used && position_ > 0)
{
character_index_[position_] = character_index_[position_ - 1];
}
position_has_been_used_[position_] = true;
updateName();