fix: bucles cap a ranges algorithms (38 troballes)

This commit is contained in:
2026-05-14 21:36:21 +02:00
parent 0aa9f8fe0a
commit b4d3776239
14 changed files with 110 additions and 169 deletions

View File

@@ -31,9 +31,9 @@ Ending2::Ending2()
// Inicializa el vector de colores
const std::vector<std::string> COLORS = {"white", "yellow", "cyan", "green", "magenta", "red", "blue", "black"};
for (const auto& color : COLORS) {
colors_.push_back(stringToColor(color));
}
colors_.reserve(COLORS.size());
std::ranges::transform(COLORS, std::back_inserter(colors_),
[](const auto& color) { return stringToColor(color); });
Screen::get()->setBorderColor(static_cast<Uint8>(PaletteColor::BLACK)); // Cambia el color del borde
iniSpriteList(); // Inicializa la lista de sprites

View File

@@ -3,6 +3,7 @@
#include <SDL3/SDL.h>
#include <cmath> // Para std::sqrt, std::min
#include <numeric> // Para std::accumulate
#include <utility>
#include <vector> // Para vector
@@ -865,14 +866,9 @@ auto Game::checkEndGame() -> bool {
// Obtiene la cantidad total de items que hay en el mapeado del juego
auto Game::getTotalItems() -> int {
int items = 0;
auto rooms = Resource::Cache::get()->getRooms();
for (const auto& room : rooms) {
items += room.room->items.size();
}
return items;
const auto& rooms = Resource::Cache::get()->getRooms();
return static_cast<int>(std::accumulate(rooms.begin(), rooms.end(), size_t{0},
[](size_t acc, const auto& room) { return acc + room.room->items.size(); }));
}
// Pone el juego en pausa

View File

@@ -38,9 +38,9 @@ GameOver::GameOver()
// Inicializa el vector de colores (de brillante a oscuro para fade)
const std::vector<std::string> COLORS = {"white", "yellow", "cyan", "green", "magenta", "red", "blue", "black"};
for (const auto& color : COLORS) {
colors_.push_back(stringToColor(color));
}
colors_.reserve(COLORS.size());
std::ranges::transform(COLORS, std::back_inserter(colors_),
[](const auto& color) { return stringToColor(color); });
color_ = colors_.back(); // Empieza en black
}

View File

@@ -259,9 +259,8 @@ void Logo::initColors() { // NOLINT(readability-convert-member-functions-to-sta
static_cast<Uint8>(PaletteColor::CYAN),
static_cast<Uint8>(PaletteColor::YELLOW),
static_cast<Uint8>(PaletteColor::BRIGHT_WHITE)};
for (const auto& color : COLORS) {
color_.push_back(color);
}
color_.reserve(COLORS.size());
std::ranges::copy(COLORS, std::back_inserter(color_));
}
// Crea los sprites de cada linea