Si no poses cap nom, tria un nom de jailer al azar

This commit is contained in:
2025-03-10 19:59:21 +01:00
parent e0c10f83d6
commit c88a277cba
6 changed files with 46 additions and 36 deletions

View File

@@ -13,7 +13,7 @@ EnterName::EnterName()
void EnterName::init(const std::string &name)
{
// No se pasa ningún nombre
if (name == "")
if (name.empty())
{
name_ = "A";
position_ = 0;
@@ -24,7 +24,7 @@ void EnterName::init(const std::string &name)
{
name_ = name;
position_ = name_.length();
position_overflow_ = position_ >= NAME_LENGHT ? true : false;
position_overflow_ = position_ >= MAX_NAME_LENGHT ? true : false;
}
// Inicializa el vector de indices con el nombre y espacios
@@ -42,15 +42,15 @@ void EnterName::incPosition()
++position_;
if (position_ >= NAME_LENGHT)
if (position_ >= MAX_NAME_LENGHT)
{
position_ = NAME_LENGHT; // Mantenemos en el índice máximo válido.
position_overflow_ = true; // Activamos el flag de overflow.
position_ = MAX_NAME_LENGHT; // Mantenemos en el índice máximo válido.
position_overflow_ = true; // Activamos el flag de overflow.
}
else
{
// Copiamos el índice del carácter anterior si es posible.
if (position_ > 0 && position_ < NAME_LENGHT)
if (position_ > 0 && position_ < MAX_NAME_LENGHT)
{
character_index_[position_] = character_index_[position_ - 1];
}
@@ -71,7 +71,7 @@ void EnterName::decPosition()
{
// Si estaba en overflow, lo desactivamos y mantenemos position_ en el máximo.
position_overflow_ = false;
position_ = NAME_LENGHT - 1;
position_ = MAX_NAME_LENGHT - 1;
}
else
{
@@ -80,7 +80,7 @@ void EnterName::decPosition()
--position_;
// Limpiamos el carácter siguiente si el índice es válido.
if (position_ + 1 < NAME_LENGHT)
if (position_ + 1 < MAX_NAME_LENGHT)
{
character_index_[position_ + 1] = 0;
}
@@ -93,7 +93,7 @@ void EnterName::decPosition()
}
// Si position_ es menor que NAME_LENGHT, aseguramos que el overflow esté desactivado.
if (position_ < NAME_LENGHT)
if (position_ < MAX_NAME_LENGHT)
{
position_overflow_ = false;
}
@@ -102,7 +102,6 @@ void EnterName::decPosition()
updateNameFromCharacterIndex();
}
// Incrementa el índice
void EnterName::incIndex()
{
@@ -126,7 +125,7 @@ void EnterName::decIndex()
{
return;
}
--character_index_[position_];
if (character_index_[position_] < 0)
{
@@ -139,7 +138,7 @@ void EnterName::decIndex()
void EnterName::updateNameFromCharacterIndex()
{
name_.clear();
for (int i = 0; i < NAME_LENGHT; ++i)
for (int i = 0; i < MAX_NAME_LENGHT; ++i)
{
name_.push_back(character_list_[character_index_[i]]);
}
@@ -150,13 +149,13 @@ void EnterName::updateNameFromCharacterIndex()
void EnterName::initCharacterIndex(const std::string &name)
{
// Rellena de espacios
for (size_t i = 0; i < NAME_LENGHT; ++i)
for (size_t i = 0; i < MAX_NAME_LENGHT; ++i)
{
character_index_[i] = 0;
}
// Coloca los índices en función de los caracteres que forman el nombre
for (size_t i = 0; i < name.substr(0, NAME_LENGHT).size(); ++i)
for (size_t i = 0; i < name.substr(0, MAX_NAME_LENGHT).size(); ++i)
{
character_index_[i] = findIndex(name.at(i));
}
@@ -166,7 +165,11 @@ void EnterName::initCharacterIndex(const std::string &name)
int EnterName::findIndex(char character) const
{
for (size_t i = 0; i < character_list_.size(); ++i)
{
if (character == character_list_.at(i))
{
return i;
}
}
return 0;
}