Pos estava ci fent arreglos varios i m'han obligat a fer commit

This commit is contained in:
2025-11-10 14:27:10 +01:00
parent b70b728b75
commit 6ea0acd3f3
8 changed files with 157 additions and 207 deletions

View File

@@ -15,13 +15,13 @@
#include "core/resources/resource_helper.hpp" // Para ResourceHelper #include "core/resources/resource_helper.hpp" // Para ResourceHelper
#include "core/system/debug.hpp" // Para Debug #include "core/system/debug.hpp" // Para Debug
#include "game/gameplay/item_tracker.hpp" // Para ItemTracker #include "game/gameplay/item_tracker.hpp" // Para ItemTracker
#include "game/gameplay/scoreboard.hpp" // Para ScoreboardData #include "game/gameplay/scoreboard.hpp" // Para Scoreboard::Data
#include "game/options.hpp" // Para Options, OptionsStats, options #include "game/options.hpp" // Para Options, OptionsStats, options
#include "utils/defines.hpp" // Para BLOCK, PLAY_AREA_HEIGHT, PLAY_AREA_WIDTH #include "utils/defines.hpp" // Para BLOCK, PLAY_AREA_HEIGHT, PLAY_AREA_WIDTH
#include "utils/utils.hpp" // Para LineHorizontal, LineDiagonal, LineVertical #include "utils/utils.hpp" // Para LineHorizontal, LineDiagonal, LineVertical
// Constructor // Constructor
Room::Room(const std::string& room_path, std::shared_ptr<ScoreboardData> data) Room::Room(const std::string& room_path, std::shared_ptr<Scoreboard::Data> data)
: data_(std::move(std::move(data))) { : data_(std::move(std::move(data))) {
auto room = Resource::get()->getRoom(room_path); auto room = Resource::get()->getRoom(room_path);
initializeRoom(*room); initializeRoom(*room);
@@ -808,35 +808,35 @@ void Room::initRoomSurfaces() {
} }
// Asigna variables a una estructura RoomData // Asigna variables a una estructura RoomData
auto Room::setRoom(Data* room, const std::string& key, const std::string& value) -> bool { auto Room::setRoom(Data& room, const std::string& key, const std::string& value) -> bool {
// Indicador de éxito en la asignación // Indicador de éxito en la asignación
bool success = true; bool success = true;
try { try {
if (key == "tileMapFile") { if (key == "tileMapFile") {
room->tile_map_file = value; room.tile_map_file = value;
} else if (key == "name") { } else if (key == "name") {
room->name = value; room.name = value;
} else if (key == "bgColor") { } else if (key == "bgColor") {
room->bg_color = value; room.bg_color = value;
} else if (key == "border") { } else if (key == "border") {
room->border_color = value; room.border_color = value;
} else if (key == "itemColor1") { } else if (key == "itemColor1") {
room->item_color1 = value; room.item_color1 = value;
} else if (key == "itemColor2") { } else if (key == "itemColor2") {
room->item_color2 = value; room.item_color2 = value;
} else if (key == "tileSetFile") { } else if (key == "tileSetFile") {
room->tile_set_file = value; room.tile_set_file = value;
} else if (key == "roomUp") { } else if (key == "roomUp") {
room->upper_room = value; room.upper_room = value;
} else if (key == "roomDown") { } else if (key == "roomDown") {
room->lower_room = value; room.lower_room = value;
} else if (key == "roomLeft") { } else if (key == "roomLeft") {
room->left_room = value; room.left_room = value;
} else if (key == "roomRight") { } else if (key == "roomRight") {
room->right_room = value; room.right_room = value;
} else if (key == "autoSurface") { } else if (key == "autoSurface") {
room->conveyor_belt_direction = (value == "right") ? 1 : -1; room.conveyor_belt_direction = (value == "right") ? 1 : -1;
} else if (key.empty() || key.substr(0, 1) == "#") { } else if (key.empty() || key.substr(0, 1) == "#") {
// No se realiza ninguna acción para estas claves // No se realiza ninguna acción para estas claves
} else { } else {
@@ -851,37 +851,37 @@ auto Room::setRoom(Data* room, const std::string& key, const std::string& value)
} }
// Asigna variables a una estructura EnemyData // Asigna variables a una estructura EnemyData
auto Room::setEnemy(Enemy::Data* enemy, const std::string& key, const std::string& value) -> bool { auto Room::setEnemy(Enemy::Data& enemy, const std::string& key, const std::string& value) -> bool {
// Indicador de éxito en la asignación // Indicador de éxito en la asignación
bool success = true; bool success = true;
try { try {
if (key == "animation") { if (key == "animation") {
enemy->animation_path = value; enemy.animation_path = value;
} else if (key == "x") { } else if (key == "x") {
enemy->x = std::stof(value) * TILE_SIZE; enemy.x = std::stof(value) * TILE_SIZE;
} else if (key == "y") { } else if (key == "y") {
enemy->y = std::stof(value) * TILE_SIZE; enemy.y = std::stof(value) * TILE_SIZE;
} else if (key == "vx") { } else if (key == "vx") {
enemy->vx = std::stof(value); enemy.vx = std::stof(value);
} else if (key == "vy") { } else if (key == "vy") {
enemy->vy = std::stof(value); enemy.vy = std::stof(value);
} else if (key == "x1") { } else if (key == "x1") {
enemy->x1 = std::stoi(value) * TILE_SIZE; enemy.x1 = std::stoi(value) * TILE_SIZE;
} else if (key == "x2") { } else if (key == "x2") {
enemy->x2 = std::stoi(value) * TILE_SIZE; enemy.x2 = std::stoi(value) * TILE_SIZE;
} else if (key == "y1") { } else if (key == "y1") {
enemy->y1 = std::stoi(value) * TILE_SIZE; enemy.y1 = std::stoi(value) * TILE_SIZE;
} else if (key == "y2") { } else if (key == "y2") {
enemy->y2 = std::stoi(value) * TILE_SIZE; enemy.y2 = std::stoi(value) * TILE_SIZE;
} else if (key == "flip") { } else if (key == "flip") {
enemy->flip = stringToBool(value); enemy.flip = stringToBool(value);
} else if (key == "mirror") { } else if (key == "mirror") {
enemy->mirror = stringToBool(value); enemy.mirror = stringToBool(value);
} else if (key == "color") { } else if (key == "color") {
enemy->color = value; enemy.color = value;
} else if (key == "frame") { } else if (key == "frame") {
enemy->frame = std::stoi(value); enemy.frame = std::stoi(value);
} else if (key == "[/enemy]" || key == "tileSetFile" || key.substr(0, 1) == "#") { } else if (key == "[/enemy]" || key == "tileSetFile" || key.substr(0, 1) == "#") {
// No se realiza ninguna acción para estas claves // No se realiza ninguna acción para estas claves
} else { } else {
@@ -896,21 +896,21 @@ auto Room::setEnemy(Enemy::Data* enemy, const std::string& key, const std::strin
} }
// Asigna variables a una estructura ItemData // Asigna variables a una estructura ItemData
auto Room::setItem(Item::Data* item, const std::string& key, const std::string& value) -> bool { auto Room::setItem(Item::Data& item, const std::string& key, const std::string& value) -> bool {
// Indicador de éxito en la asignación // Indicador de éxito en la asignación
bool success = true; bool success = true;
try { try {
if (key == "tileSetFile") { if (key == "tileSetFile") {
item->tile_set_file = value; item.tile_set_file = value;
} else if (key == "counter") { } else if (key == "counter") {
item->counter = std::stoi(value); item.counter = std::stoi(value);
} else if (key == "x") { } else if (key == "x") {
item->x = std::stof(value) * TILE_SIZE; item.x = std::stof(value) * TILE_SIZE;
} else if (key == "y") { } else if (key == "y") {
item->y = std::stof(value) * TILE_SIZE; item.y = std::stof(value) * TILE_SIZE;
} else if (key == "tile") { } else if (key == "tile") {
item->tile = std::stof(value); item.tile = std::stof(value);
} else if (key == "[/item]") { } else if (key == "[/item]") {
// No se realiza ninguna acción para esta clave // No se realiza ninguna acción para esta clave
} else { } else {
@@ -1017,7 +1017,7 @@ auto Room::loadRoomFile(const std::string& file_path, bool verbose) -> Data {
// En caso contrario se parsea el fichero para buscar las variables y los valores // En caso contrario se parsea el fichero para buscar las variables y los valores
else { else {
auto [key, value] = parseKeyValue(line); auto [key, value] = parseKeyValue(line);
if (!setRoom(&room, key, value)) { if (!setRoom(room, key, value)) {
logUnknownParameter(FILE_NAME, key, verbose); logUnknownParameter(FILE_NAME, key, verbose);
} }
} }
@@ -1064,7 +1064,7 @@ auto Room::loadEnemyFromFile(std::istream& file, const std::string& file_name, b
} }
auto [key, value] = parseKeyValue(line); auto [key, value] = parseKeyValue(line);
if (!setEnemy(&enemy, key, value)) { if (!setEnemy(enemy, key, value)) {
logUnknownParameter(file_name, key, verbose); logUnknownParameter(file_name, key, verbose);
} }
} while (line != "[/enemy]"); } while (line != "[/enemy]");
@@ -1088,7 +1088,7 @@ auto Room::loadItemFromFile(std::istream& file, const std::string& file_name, bo
} }
auto [key, value] = parseKeyValue(line); auto [key, value] = parseKeyValue(line);
if (!setItem(&item, key, value)) { if (!setItem(item, key, value)) {
logUnknownParameter(file_name, key, verbose); logUnknownParameter(file_name, key, verbose);
} }
} while (line != "[/item]"); } while (line != "[/item]");

View File

@@ -8,10 +8,10 @@
#include "game/entities/enemy.hpp" // Para EnemyData #include "game/entities/enemy.hpp" // Para EnemyData
#include "game/entities/item.hpp" // Para ItemData #include "game/entities/item.hpp" // Para ItemData
#include "game/gameplay/scoreboard.hpp" // Para Scoreboard::Data
#include "utils/utils.hpp" // Para LineHorizontal, LineDiagonal, LineVertical #include "utils/utils.hpp" // Para LineHorizontal, LineDiagonal, LineVertical
class SurfaceSprite; // lines 12-12 class SurfaceSprite; // lines 12-12
class Surface; // lines 13-13 class Surface; // lines 13-13
struct ScoreboardData; // lines 15-15
class Room { class Room {
public: public:
@@ -53,7 +53,7 @@ class Room {
}; };
// Constructor y destructor // Constructor y destructor
Room(const std::string& room_path, std::shared_ptr<ScoreboardData> data); Room(const std::string& room_path, std::shared_ptr<Scoreboard::Data> data);
~Room() = default; ~Room() = default;
// --- Funciones --- // --- Funciones ---
@@ -104,7 +104,7 @@ class Room {
std::vector<std::shared_ptr<Item>> items_; // Listado con los items que hay en la habitación std::vector<std::shared_ptr<Item>> items_; // Listado con los items que hay en la habitación
std::shared_ptr<Surface> surface_; // Textura con los graficos de la habitación std::shared_ptr<Surface> surface_; // Textura con los graficos de la habitación
std::shared_ptr<Surface> map_surface_; // Textura para dibujar el mapa de la habitación std::shared_ptr<Surface> map_surface_; // Textura para dibujar el mapa de la habitación
std::shared_ptr<ScoreboardData> data_; // Puntero a los datos del marcador std::shared_ptr<Scoreboard::Data> data_; // Puntero a los datos del marcador
// --- Variables --- // --- Variables ---
std::string number_; // Numero de la habitación std::string number_; // Numero de la habitación
@@ -153,9 +153,9 @@ class Room {
auto getTile(int index) -> Tile; // Devuelve el tipo de tile que hay en ese indice auto getTile(int index) -> Tile; // Devuelve el tipo de tile que hay en ese indice
void openTheJail(); // Abre la jail para poder entrar void openTheJail(); // Abre la jail para poder entrar
void initRoomSurfaces(); // Inicializa las superficies de colision void initRoomSurfaces(); // Inicializa las superficies de colision
static auto setRoom(Data* room, const std::string& key, const std::string& value) -> bool; // Asigna variables a una estructura RoomData static auto setRoom(Data& room, const std::string& key, const std::string& value) -> bool; // Asigna variables a una estructura RoomData
static auto setEnemy(Enemy::Data* enemy, const std::string& key, const std::string& value) -> bool; // Asigna variables a una estructura EnemyData static auto setEnemy(Enemy::Data& enemy, const std::string& key, const std::string& value) -> bool; // Asigna variables a una estructura EnemyData
static auto setItem(Item::Data* item, const std::string& key, const std::string& value) -> bool; // Asigna variables a una estructura ItemData static auto setItem(Item::Data& item, const std::string& key, const std::string& value) -> bool; // Asigna variables a una estructura ItemData
static auto parseKeyValue(const std::string& line) -> std::pair<std::string, std::string>; static auto parseKeyValue(const std::string& line) -> std::pair<std::string, std::string>;
static void logUnknownParameter(const std::string& file_name, const std::string& key, bool verbose); static void logUnknownParameter(const std::string& file_name, const std::string& key, bool verbose);
static auto loadEnemyFromFile(std::istream& file, const std::string& file_name, bool verbose) -> Enemy::Data; static auto loadEnemyFromFile(std::istream& file, const std::string& file_name, bool verbose) -> Enemy::Data;

View File

@@ -14,7 +14,7 @@
#include "utils/utils.hpp" // Para stringToColor #include "utils/utils.hpp" // Para stringToColor
// Constructor // Constructor
Scoreboard::Scoreboard(std::shared_ptr<ScoreboardData> data) Scoreboard::Scoreboard(std::shared_ptr<Data> data)
: item_surface_(Resource::get()->getSurface("items.gif")), : item_surface_(Resource::get()->getSurface("items.gif")),
data_(std::move(std::move(data))) { data_(std::move(std::move(data))) {
const float SURFACE_WIDTH = Options::game.width; const float SURFACE_WIDTH = Options::game.width;
@@ -29,10 +29,7 @@ Scoreboard::Scoreboard(std::shared_ptr<ScoreboardData> data)
surface_ = std::make_shared<Surface>(SURFACE_WIDTH, SURFACE_HEIGHT); surface_ = std::make_shared<Surface>(SURFACE_WIDTH, SURFACE_HEIGHT);
surface_dest_ = {.x = 0, .y = Options::game.height - SURFACE_HEIGHT, .w = SURFACE_WIDTH, .h = SURFACE_HEIGHT}; surface_dest_ = {.x = 0, .y = Options::game.height - SURFACE_HEIGHT, .w = SURFACE_WIDTH, .h = SURFACE_HEIGHT};
// Inicializa las variables // Inicializa el color de items
is_paused_ = false;
paused_time_ = 0;
paused_time_elapsed_ = 0;
items_color_ = stringToColor("white"); items_color_ = stringToColor("white");
// Inicializa el vector de colores // Inicializa el vector de colores

View File

@@ -9,106 +9,60 @@
class SurfaceAnimatedSprite; // lines 10-10 class SurfaceAnimatedSprite; // lines 10-10
class Surface; // lines 11-11 class Surface; // lines 11-11
struct ScoreboardData {
int items; // Lleva la cuenta de los objetos recogidos
int lives; // Lleva la cuenta de las vidas restantes del jugador
int rooms; // Lleva la cuenta de las habitaciones visitadas
bool music; // Indica si ha de sonar la música durante el juego
Uint8 color; // Color para escribir el texto del marcador
Uint32 ini_clock; // Tiempo inicial para calcular el tiempo transcurrido
bool jail_is_open; // Indica si se puede entrar a la Jail
// Constructor por defecto
ScoreboardData()
: items(0),
lives(0),
rooms(0),
music(true),
color(0),
ini_clock(0),
jail_is_open(false) {}
// Constructor parametrizado
ScoreboardData(int items, int lives, int rooms, bool music, Uint8 color, Uint32 ini_clock, bool jail_is_open)
: items(items),
lives(lives),
rooms(rooms),
music(music),
color(color),
ini_clock(ini_clock),
jail_is_open(jail_is_open) {}
};
class Scoreboard { class Scoreboard {
private: public:
struct ClockData { // Tipos anidados
int hours; struct Data {
int minutes; int items{0}; // Lleva la cuenta de los objetos recogidos
int seconds; int lives{0}; // Lleva la cuenta de las vidas restantes del jugador
std::string separator; int rooms{0}; // Lleva la cuenta de las habitaciones visitadas
bool music{true}; // Indica si ha de sonar la música durante el juego
// Constructor por defecto Uint8 color{0}; // Color para escribir el texto del marcador
ClockData() Uint32 ini_clock{0}; // Tiempo inicial para calcular el tiempo transcurrido
: hours(0), bool jail_is_open{false}; // Indica si se puede entrar a la Jail
minutes(0),
seconds(0),
separator(":") {}
// Constructor parametrizado
ClockData(int h, int m, int s, std::string sep)
: hours(h),
minutes(m),
seconds(s),
separator(std::move(sep)) {}
}; };
// Objetos y punteros // Métodos públicos
std::shared_ptr<SurfaceAnimatedSprite> player_sprite_; // Sprite para mostrar las vidas en el marcador explicit Scoreboard(std::shared_ptr<Data> data); // Constructor
std::shared_ptr<Surface> item_surface_; // Surface con los graficos para los elementos del marcador ~Scoreboard() = default; // Destructor
std::shared_ptr<ScoreboardData> data_; // Contiene las variables a mostrar en el marcador void render(); // Pinta el objeto en pantalla
std::shared_ptr<Surface> surface_; // Surface donde dibujar el marcador; void update(float delta_time); // Actualiza las variables del objeto
void setPaused(bool value); // Pone el marcador en modo pausa
auto getMinutes() -> int; // Devuelve la cantidad de minutos de juego transcurridos
private:
// Tipos anidados
struct ClockData {
int hours{0}; // Horas transcurridas
int minutes{0}; // Minutos transcurridos
int seconds{0}; // Segundos transcurridos
std::string separator{":"}; // Separador para mostrar el tiempo
};
// Constantes de tiempo // Constantes de tiempo
static constexpr float ITEMS_COLOR_BLINK_DURATION = 0.333F; // Duración de cada estado del parpadeo (era 10 frames @ 60fps) static constexpr float ITEMS_COLOR_BLINK_DURATION = 0.333F; // Duración de cada estado del parpadeo (era 10 frames @ 60fps)
static constexpr float SPRITE_WALK_CYCLE_DURATION = 0.667F; // Duración del ciclo de caminar (era 40 frames @ 60fps) static constexpr float SPRITE_WALK_CYCLE_DURATION = 0.667F; // Duración del ciclo de caminar (era 40 frames @ 60fps)
static constexpr int SPRITE_WALK_FRAMES = 4; // Número de frames de animación static constexpr int SPRITE_WALK_FRAMES = 4; // Número de frames de animación
// Variables // Métodos privados
auto getTime() -> ClockData; // Obtiene el tiempo transcurrido de partida
void updateItemsColor(float delta_time); // Actualiza el color de la cantidad de items recogidos
void fillTexture(); // Dibuja los elementos del marcador en la surface
// Objetos y punteros
std::shared_ptr<SurfaceAnimatedSprite> player_sprite_; // Sprite para mostrar las vidas en el marcador
std::shared_ptr<Surface> item_surface_; // Surface con los graficos para los elementos del marcador
std::shared_ptr<Data> data_; // Contiene las variables a mostrar en el marcador
std::shared_ptr<Surface> surface_; // Surface donde dibujar el marcador
// Variables de estado
std::vector<Uint8> color_; // Vector con los colores del objeto std::vector<Uint8> color_; // Vector con los colores del objeto
bool is_paused_; // Indica si el marcador esta en modo pausa bool is_paused_{false}; // Indica si el marcador esta en modo pausa
Uint32 paused_time_; // Milisegundos que ha estado el marcador en pausa Uint32 paused_time_{0}; // Milisegundos que ha estado el marcador en pausa
Uint32 paused_time_elapsed_; // Tiempo acumulado en pausa Uint32 paused_time_elapsed_{0}; // Tiempo acumulado en pausa
ClockData clock_; // Contiene las horas, minutos y segundos transcurridos desde el inicio de la partida ClockData clock_{}; // Contiene las horas, minutos y segundos transcurridos desde el inicio de la partida
Uint8 items_color_; // Color de la cantidad de items recogidos Uint8 items_color_{0}; // Color de la cantidad de items recogidos
SDL_FRect surface_dest_; // Rectangulo donde dibujar la surface del marcador SDL_FRect surface_dest_{}; // Rectangulo donde dibujar la surface del marcador
float time_accumulator_ = 0.0F; // Acumulador de tiempo para animaciones float time_accumulator_{0.0F}; // Acumulador de tiempo para animaciones
float items_color_timer_ = 0.0F; // Timer para parpadeo de color de items float items_color_timer_{0.0F}; // Timer para parpadeo de color de items
// Obtiene el tiempo transcurrido de partida
auto getTime() -> ClockData;
// Actualiza el color de la cantidad de items recogidos
void updateItemsColor(float delta_time);
// Dibuja los elementos del marcador en la surface
void fillTexture();
public:
// Constructor
explicit Scoreboard(std::shared_ptr<ScoreboardData> data);
// Destructor
~Scoreboard() = default;
// Pinta el objeto en pantalla
void render();
// Actualiza las variables del objeto
void update(float delta_time);
// Pone el marcador en modo pausa
void setPaused(bool value);
// Devuelve la cantidad de minutos de juego transcurridos
auto getMinutes() -> int;
}; };

View File

@@ -49,7 +49,7 @@ void Stats::addDeath(const std::string& name) {
// En caso contrario crea la entrada // En caso contrario crea la entrada
else { else {
StatsData item; RoomData item;
item.name = name; item.name = name;
item.visited = 0; item.visited = 0;
item.died = 1; item.died = 1;
@@ -67,7 +67,7 @@ void Stats::addVisit(const std::string& name) {
// En caso contrario crea la entrada // En caso contrario crea la entrada
else { else {
StatsData item; RoomData item;
item.name = name; item.name = name;
item.visited = 1; item.visited = 1;
item.died = 0; item.died = 0;
@@ -76,7 +76,7 @@ void Stats::addVisit(const std::string& name) {
} }
// Busca una entrada en la lista por nombre // Busca una entrada en la lista por nombre
auto Stats::findByName(const std::string& name, const std::vector<StatsData>& list) -> int { auto Stats::findByName(const std::string& name, const std::vector<RoomData>& list) -> int {
int i = 0; int i = 0;
for (const auto& l : list) { for (const auto& l : list) {
@@ -90,7 +90,7 @@ auto Stats::findByName(const std::string& name, const std::vector<StatsData>& li
} }
// Carga las estadisticas desde un fichero // Carga las estadisticas desde un fichero
auto Stats::loadFromFile(const std::string& file_path, std::vector<StatsData>& list) -> bool { auto Stats::loadFromFile(const std::string& file_path, std::vector<RoomData>& list) -> bool {
list.clear(); list.clear();
// Indicador de éxito en la carga // Indicador de éxito en la carga
@@ -110,7 +110,7 @@ auto Stats::loadFromFile(const std::string& file_path, std::vector<StatsData>& l
} }
// Comprueba que la linea no sea un comentario // Comprueba que la linea no sea un comentario
if (line.substr(0, 1) != "#") { if (line.substr(0, 1) != "#") {
StatsData stat; RoomData stat;
std::stringstream ss(line); std::stringstream ss(line);
std::string tmp; std::string tmp;
@@ -144,7 +144,7 @@ auto Stats::loadFromFile(const std::string& file_path, std::vector<StatsData>& l
} }
// Guarda las estadisticas en un fichero // Guarda las estadisticas en un fichero
void Stats::saveToFile(const std::string& file_path, const std::vector<StatsData>& list) { void Stats::saveToFile(const std::string& file_path, const std::vector<RoomData>& list) {
// Crea y abre el fichero de texto // Crea y abre el fichero de texto
std::ofstream file(file_path); std::ofstream file(file_path);
@@ -184,7 +184,7 @@ void Stats::updateListFromBuffer() {
list_[index].visited += buffer.visited; list_[index].visited += buffer.visited;
list_[index].died += buffer.died; list_[index].died += buffer.died;
} else { // En caso contrario crea la entrada } else { // En caso contrario crea la entrada
StatsData item; RoomData item;
item.name = buffer.name; item.name = buffer.name;
item.visited = buffer.visited; item.visited = buffer.visited;
item.died = buffer.died; item.died = buffer.died;

View File

@@ -5,32 +5,32 @@
class Stats { class Stats {
private: private:
struct StatsData { struct RoomData {
std::string name; // Nombre de la habitación std::string name; // Nombre de la habitación
int visited; // Cuenta las veces que se ha visitado una habitación int visited; // Cuenta las veces que se ha visitado una habitación
int died; // Cuenta las veces que se ha muerto en una habitación int died; // Cuenta las veces que se ha muerto en una habitación
}; };
struct StatsDictionary { struct Dictionary {
std::string number; // Numero de la habitación std::string number; // Numero de la habitación
std::string name; // Nombre de la habitación std::string name; // Nombre de la habitación
}; };
// Variables // Variables
std::vector<StatsDictionary> dictionary_; // Lista con la equivalencia nombre-numero de habitacion std::vector<Dictionary> dictionary_; // Lista con la equivalencia nombre-numero de habitacion
std::vector<StatsData> buffer_list_; // Lista con las estadisticas temporales por habitación std::vector<RoomData> buffer_list_; // Lista con las estadisticas temporales por habitación
std::vector<StatsData> list_; // Lista con las estadisticas completas por habitación std::vector<RoomData> list_; // Lista con las estadisticas completas por habitación
std::string buffer_path_; // Fichero con las estadísticas temporales std::string buffer_path_; // Fichero con las estadísticas temporales
std::string file_path_; // Fichero con las estadísticas completas std::string file_path_; // Fichero con las estadísticas completas
// Busca una entrada en la lista por nombre // Busca una entrada en la lista por nombre
static auto findByName(const std::string& name, const std::vector<StatsData>& list) -> int; static auto findByName(const std::string& name, const std::vector<RoomData>& list) -> int;
// Carga las estadisticas desde un fichero // Carga las estadisticas desde un fichero
static auto loadFromFile(const std::string& file_path, std::vector<StatsData>& list) -> bool; static auto loadFromFile(const std::string& file_path, std::vector<RoomData>& list) -> bool;
// Guarda las estadisticas en un fichero // Guarda las estadisticas en un fichero
static void saveToFile(const std::string& file_path, const std::vector<StatsData>& list); static void saveToFile(const std::string& file_path, const std::vector<RoomData>& list);
// Calcula cual es la habitación con más muertes // Calcula cual es la habitación con más muertes
void checkWorstNightmare(); void checkWorstNightmare();

View File

@@ -18,7 +18,7 @@
#include "game/gameplay/item_tracker.hpp" // Para ItemTracker #include "game/gameplay/item_tracker.hpp" // Para ItemTracker
#include "game/gameplay/room.hpp" // Para Room, RoomData #include "game/gameplay/room.hpp" // Para Room, RoomData
#include "game/gameplay/room_tracker.hpp" // Para RoomTracker #include "game/gameplay/room_tracker.hpp" // Para RoomTracker
#include "game/gameplay/scoreboard.hpp" // Para ScoreboardData, Scoreboard #include "game/gameplay/scoreboard.hpp" // Para Scoreboard::Data, Scoreboard
#include "game/gameplay/stats.hpp" // Para Stats #include "game/gameplay/stats.hpp" // Para Stats
#include "game/options.hpp" // Para Options, options, Cheat, SectionState #include "game/options.hpp" // Para Options, options, Cheat, SectionState
#include "game/scene_manager.hpp" // Para SceneManager #include "game/scene_manager.hpp" // Para SceneManager
@@ -32,7 +32,7 @@
// Constructor // Constructor
Game::Game(Mode mode) Game::Game(Mode mode)
: board_(std::make_shared<ScoreboardData>(0, 9, 0, true, 0, SDL_GetTicks(), Options::cheats.jail_is_open == Options::Cheat::State::ENABLED)), : board_(std::make_shared<Scoreboard::Data>(0, 9, 0, true, 0, SDL_GetTicks(), Options::cheats.jail_is_open == Options::Cheat::State::ENABLED)),
scoreboard_(std::make_shared<Scoreboard>(board_)), scoreboard_(std::make_shared<Scoreboard>(board_)),
room_tracker_(std::make_shared<RoomTracker>()), room_tracker_(std::make_shared<RoomTracker>()),
stats_(std::make_shared<Stats>(Asset::get()->get("stats.csv"), Asset::get()->get("stats_buffer.csv"))), stats_(std::make_shared<Stats>(Asset::get()->get("stats.csv"), Asset::get()->get("stats_buffer.csv"))),
@@ -486,9 +486,9 @@ void Game::checkRestoringJail(float delta_time) {
// Inicializa el diccionario de las estadísticas // Inicializa el diccionario de las estadísticas
void Game::initStats() { void Game::initStats() {
auto rooms = Resource::get()->getRooms(); auto list = Resource::get()->getRooms();
for (const auto& room : rooms) { for (const auto& room : list) {
stats_->addDictionary(room.room->number, room.room->name); stats_->addDictionary(room.room->number, room.room->name);
} }

View File

@@ -14,7 +14,6 @@ class RoomTracker; // lines 13-13
class Scoreboard; // lines 14-14 class Scoreboard; // lines 14-14
class Stats; // lines 15-15 class Stats; // lines 15-15
class Surface; class Surface;
struct ScoreboardData; // lines 16-16
class Game { class Game {
public: public:
@@ -83,7 +82,7 @@ class Game {
// --- Variables miembro --- // --- Variables miembro ---
// Objetos y punteros a recursos // Objetos y punteros a recursos
std::shared_ptr<ScoreboardData> board_; // Estructura con los datos del marcador std::shared_ptr<Scoreboard::Data> board_; // Estructura con los datos del marcador
std::shared_ptr<Scoreboard> scoreboard_; // Objeto encargado de gestionar el marcador std::shared_ptr<Scoreboard> scoreboard_; // Objeto encargado de gestionar el marcador
std::shared_ptr<RoomTracker> room_tracker_; // Lleva el control de las habitaciones visitadas std::shared_ptr<RoomTracker> room_tracker_; // Lleva el control de las habitaciones visitadas
std::shared_ptr<Room> room_; // Objeto encargado de gestionar cada habitación del juego std::shared_ptr<Room> room_; // Objeto encargado de gestionar cada habitación del juego