forked from jaildesigner-jailgames/jaildoctors_dilemma
linter
This commit is contained in:
@@ -10,21 +10,21 @@
|
||||
#include "game/ui/notifier.hpp" // Para Notifier
|
||||
|
||||
// [SINGLETON]
|
||||
Cheevos* Cheevos::cheevos_ = nullptr;
|
||||
Cheevos* Cheevos::cheevos = nullptr;
|
||||
|
||||
// [SINGLETON] Crearemos el objeto con esta función estática
|
||||
void Cheevos::init(const std::string& file) {
|
||||
Cheevos::cheevos_ = new Cheevos(file);
|
||||
Cheevos::cheevos = new Cheevos(file);
|
||||
}
|
||||
|
||||
// [SINGLETON] Destruiremos el objeto con esta función estática
|
||||
void Cheevos::destroy() {
|
||||
delete Cheevos::cheevos_;
|
||||
delete Cheevos::cheevos;
|
||||
}
|
||||
|
||||
// [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él
|
||||
Cheevos* Cheevos::get() {
|
||||
return Cheevos::cheevos_;
|
||||
return Cheevos::cheevos;
|
||||
}
|
||||
|
||||
// Constructor
|
||||
@@ -88,11 +88,11 @@ void Cheevos::unlock(int id) {
|
||||
|
||||
// Invalida un logro
|
||||
void Cheevos::setUnobtainable(int id) {
|
||||
const int index = find(id);
|
||||
const int INDEX = find(id);
|
||||
|
||||
// Si el índice es válido, se invalida el logro
|
||||
if (index != -1) {
|
||||
cheevos_list_.at(index).obtainable = false;
|
||||
if (INDEX != -1) {
|
||||
cheevos_list_.at(INDEX).obtainable = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,16 +107,16 @@ void Cheevos::loadFromFile() {
|
||||
}
|
||||
|
||||
// Crea el fichero en modo escritura (binario)
|
||||
std::ofstream newFile(file_, std::ios::binary);
|
||||
std::ofstream new_file(file_, std::ios::binary);
|
||||
|
||||
if (newFile) {
|
||||
if (new_file) {
|
||||
if (Options::console) {
|
||||
std::cout << "New " << file_ << " created!" << std::endl;
|
||||
}
|
||||
|
||||
// Guarda la información
|
||||
for (const auto& cheevo : cheevos_list_) {
|
||||
newFile.write(reinterpret_cast<const char*>(&cheevo.completed), sizeof(bool));
|
||||
new_file.write(reinterpret_cast<const char*>(&cheevo.completed), sizeof(bool));
|
||||
}
|
||||
} else {
|
||||
if (Options::console) {
|
||||
|
||||
@@ -32,7 +32,7 @@ struct Achievement {
|
||||
class Cheevos {
|
||||
private:
|
||||
// [SINGLETON] Objeto privado
|
||||
static Cheevos* cheevos_;
|
||||
static Cheevos* cheevos;
|
||||
|
||||
// Variables
|
||||
std::vector<Achievement> cheevos_list_; // Listado de logros
|
||||
|
||||
@@ -1,29 +1,29 @@
|
||||
#include "game/gameplay/item_tracker.hpp"
|
||||
|
||||
// [SINGLETON]
|
||||
ItemTracker* ItemTracker::item_tracker_ = nullptr;
|
||||
ItemTracker* ItemTracker::item_tracker = nullptr;
|
||||
|
||||
// [SINGLETON] Crearemos el objeto con esta función estática
|
||||
void ItemTracker::init() {
|
||||
ItemTracker::item_tracker_ = new ItemTracker();
|
||||
ItemTracker::item_tracker = new ItemTracker();
|
||||
}
|
||||
|
||||
// [SINGLETON] Destruiremos el objeto con esta función estática
|
||||
void ItemTracker::destroy() {
|
||||
delete ItemTracker::item_tracker_;
|
||||
delete ItemTracker::item_tracker;
|
||||
}
|
||||
|
||||
// [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él
|
||||
ItemTracker* ItemTracker::get() {
|
||||
return ItemTracker::item_tracker_;
|
||||
return ItemTracker::item_tracker;
|
||||
}
|
||||
|
||||
// Comprueba si el objeto ya ha sido cogido
|
||||
bool ItemTracker::hasBeenPicked(const std::string& name, SDL_FPoint pos) {
|
||||
// Primero busca si ya hay una entrada con ese nombre
|
||||
if (const int index = findByName(name); index != -1) {
|
||||
if (const int INDEX = findByName(name); INDEX != -1) {
|
||||
// Luego busca si existe ya una entrada con esa posición
|
||||
if (findByPos(index, pos) != -1) {
|
||||
if (findByPos(INDEX, pos) != -1) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -36,8 +36,8 @@ void ItemTracker::addItem(const std::string& name, SDL_FPoint pos) {
|
||||
// Comprueba si el objeto no ha sido recogido con anterioridad
|
||||
if (!hasBeenPicked(name, pos)) {
|
||||
// Primero busca si ya hay una entrada con ese nombre
|
||||
if (const int index = findByName(name); index != -1) {
|
||||
item_list_.at(index).pos.push_back(pos);
|
||||
if (const int INDEX = findByName(name); INDEX != -1) {
|
||||
item_list_.at(INDEX).pos.push_back(pos);
|
||||
}
|
||||
// En caso contrario crea la entrada
|
||||
else {
|
||||
|
||||
@@ -19,7 +19,7 @@ struct ItemTrackerData {
|
||||
class ItemTracker {
|
||||
private:
|
||||
// [SINGLETON] Objeto privado
|
||||
static ItemTracker* item_tracker_;
|
||||
static ItemTracker* item_tracker;
|
||||
|
||||
// Variables
|
||||
std::vector<ItemTrackerData> item_list_; // Lista con todos los objetos recogidos
|
||||
|
||||
@@ -19,8 +19,8 @@
|
||||
|
||||
// Carga las variables y texturas desde un fichero de mapa de tiles
|
||||
std::vector<int> loadRoomTileFile(const std::string& file_path, bool verbose) {
|
||||
std::vector<int> tileMapFile;
|
||||
const std::string filename = file_path.substr(file_path.find_last_of("\\/") + 1);
|
||||
std::vector<int> tile_map_file;
|
||||
const std::string FILENAME = file_path.substr(file_path.find_last_of("\\/") + 1);
|
||||
std::ifstream file(file_path);
|
||||
|
||||
// El fichero se puede abrir
|
||||
@@ -35,7 +35,7 @@ std::vector<int> loadRoomTileFile(const std::string& file_path, bool verbose) {
|
||||
std::stringstream ss(line);
|
||||
std::string tmp;
|
||||
while (getline(ss, tmp, ',')) {
|
||||
tileMapFile.push_back(std::stoi(tmp) - 1);
|
||||
tile_map_file.push_back(std::stoi(tmp) - 1);
|
||||
}
|
||||
|
||||
// Lee la siguiente linea
|
||||
@@ -46,18 +46,18 @@ std::vector<int> loadRoomTileFile(const std::string& file_path, bool verbose) {
|
||||
|
||||
// Cierra el fichero
|
||||
if (verbose) {
|
||||
std::cout << "TileMap loaded: " << filename.c_str() << std::endl;
|
||||
std::cout << "TileMap loaded: " << FILENAME.c_str() << std::endl;
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
|
||||
else { // El fichero no se puede abrir
|
||||
if (verbose) {
|
||||
std::cout << "Warning: Unable to open " << filename.c_str() << " file" << std::endl;
|
||||
std::cout << "Warning: Unable to open " << FILENAME.c_str() << " file" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
return tileMapFile;
|
||||
return tile_map_file;
|
||||
}
|
||||
|
||||
// Carga las variables desde un fichero de mapa
|
||||
@@ -67,8 +67,8 @@ RoomData loadRoomFile(const std::string& file_path, bool verbose) {
|
||||
room.item_color2 = "magenta";
|
||||
room.conveyor_belt_direction = 1;
|
||||
|
||||
const std::string fileName = file_path.substr(file_path.find_last_of("\\/") + 1);
|
||||
room.number = fileName.substr(0, fileName.find_last_of("."));
|
||||
const std::string FILE_NAME = file_path.substr(file_path.find_last_of("\\/") + 1);
|
||||
room.number = FILE_NAME.substr(0, FILE_NAME.find_last_of("."));
|
||||
|
||||
std::ifstream file(file_path);
|
||||
|
||||
@@ -93,10 +93,11 @@ RoomData loadRoomFile(const std::string& file_path, bool verbose) {
|
||||
// Procesa las dos subcadenas
|
||||
std::string key = line.substr(0, pos);
|
||||
std::string value = line.substr(pos + 1, line.length());
|
||||
if (!setEnemy(&enemy, key, value))
|
||||
if (!setEnemy(&enemy, key, value)) {
|
||||
if (verbose) {
|
||||
std::cout << "Warning: file " << fileName.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl;
|
||||
std::cout << "Warning: file " << FILE_NAME.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl;
|
||||
}
|
||||
}
|
||||
} while (line != "[/enemy]");
|
||||
|
||||
// Añade el enemigo al vector de enemigos
|
||||
@@ -121,7 +122,7 @@ RoomData loadRoomFile(const std::string& file_path, bool verbose) {
|
||||
std::string value = line.substr(pos + 1, line.length());
|
||||
if (!setItem(&item, key, value)) {
|
||||
if (verbose) {
|
||||
std::cout << "Warning: file " << fileName.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl;
|
||||
std::cout << "Warning: file " << FILE_NAME.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,7 +141,7 @@ RoomData loadRoomFile(const std::string& file_path, bool verbose) {
|
||||
std::string value = line.substr(pos + 1, line.length());
|
||||
if (!setRoom(&room, key, value)) {
|
||||
if (verbose) {
|
||||
std::cout << "Warning: file " << fileName.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl;
|
||||
std::cout << "Warning: file " << FILE_NAME.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -148,14 +149,14 @@ RoomData loadRoomFile(const std::string& file_path, bool verbose) {
|
||||
|
||||
// Cierra el fichero
|
||||
if (verbose) {
|
||||
std::cout << "Room loaded: " << fileName.c_str() << std::endl;
|
||||
std::cout << "Room loaded: " << FILE_NAME.c_str() << std::endl;
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
// El fichero no se puede abrir
|
||||
else {
|
||||
{
|
||||
std::cout << "Warning: Unable to open " << fileName.c_str() << " file" << std::endl;
|
||||
std::cout << "Warning: Unable to open " << FILE_NAME.c_str() << " file" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,7 +193,7 @@ bool setRoom(RoomData* room, const std::string& key, const std::string& value) {
|
||||
room->right_room = value;
|
||||
} else if (key == "autoSurface") {
|
||||
room->conveyor_belt_direction = (value == "right") ? 1 : -1;
|
||||
} else if (key == "" || key.substr(0, 1) == "#") {
|
||||
} else if (key.empty() || key.substr(0, 1) == "#") {
|
||||
// No se realiza ninguna acción para estas claves
|
||||
} else {
|
||||
success = false;
|
||||
@@ -327,56 +328,57 @@ void Room::initializeRoom(const RoomData& room) {
|
||||
conveyor_belt_direction_ = room.conveyor_belt_direction;
|
||||
tile_map_ = Resource::get()->getTileMap(room.tile_map_file);
|
||||
surface_ = Resource::get()->getSurface(room.tile_set_file);
|
||||
tile_set_width_ = surface_->getWidth() / TILE_SIZE_;
|
||||
tile_set_width_ = surface_->getWidth() / TILE_SIZE;
|
||||
is_paused_ = false;
|
||||
counter_ = 0;
|
||||
|
||||
// Crear los enemigos
|
||||
for (auto& enemy_data : room.enemies) {
|
||||
for (const auto& enemy_data : room.enemies) {
|
||||
enemies_.emplace_back(std::make_shared<Enemy>(enemy_data));
|
||||
}
|
||||
|
||||
// Crear los items
|
||||
for (const auto& item : room.items) {
|
||||
const SDL_FPoint itemPos = {item.x, item.y};
|
||||
const SDL_FPoint ITEM_POS = {item.x, item.y};
|
||||
|
||||
if (!ItemTracker::get()->hasBeenPicked(room.name, itemPos)) {
|
||||
if (!ItemTracker::get()->hasBeenPicked(room.name, ITEM_POS)) {
|
||||
// Crear una copia local de los datos del item
|
||||
ItemData itemCopy = item;
|
||||
itemCopy.color1 = stringToColor(item_color1_);
|
||||
itemCopy.color2 = stringToColor(item_color2_);
|
||||
ItemData item_copy = item;
|
||||
item_copy.color1 = stringToColor(item_color1_);
|
||||
item_copy.color2 = stringToColor(item_color2_);
|
||||
|
||||
// Crear el objeto Item usando la copia modificada
|
||||
items_.emplace_back(std::make_shared<Item>(itemCopy));
|
||||
items_.emplace_back(std::make_shared<Item>(item_copy));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Crea la textura con el mapeado de la habitación
|
||||
void Room::fillMapTexture() {
|
||||
const Uint8 color = stringToColor(bg_color_);
|
||||
const Uint8 COLOR = stringToColor(bg_color_);
|
||||
auto previuos_renderer = Screen::get()->getRendererSurface();
|
||||
Screen::get()->setRendererSurface(map_surface_);
|
||||
map_surface_->clear(color);
|
||||
map_surface_->clear(COLOR);
|
||||
|
||||
// Los tileSetFiles son de 20x20 tiles. El primer tile es el 0. Cuentan hacia la derecha y hacia abajo
|
||||
|
||||
SDL_FRect clip = {0, 0, TILE_SIZE_, TILE_SIZE_};
|
||||
for (int y = 0; y < MAP_HEIGHT_; ++y)
|
||||
for (int x = 0; x < MAP_WIDTH_; ++x) {
|
||||
SDL_FRect clip = {0, 0, TILE_SIZE, TILE_SIZE};
|
||||
for (int y = 0; y < MAP_HEIGHT; ++y) {
|
||||
for (int x = 0; x < MAP_WIDTH; ++x) {
|
||||
// Tiled pone los tiles vacios del mapa como cero y empieza a contar de 1 a n.
|
||||
// Al cargar el mapa en memoria, se resta uno, por tanto los tiles vacios son -1
|
||||
// Tampoco hay que dibujar los tiles animados que estan en la fila 19 (indices)
|
||||
const int INDEX = (y * MAP_WIDTH_) + x;
|
||||
const int INDEX = (y * MAP_WIDTH) + x;
|
||||
const bool A = (tile_map_[INDEX] >= 18 * tile_set_width_) && (tile_map_[INDEX] < 19 * tile_set_width_);
|
||||
const bool B = tile_map_[INDEX] > -1;
|
||||
|
||||
if (B && !A) {
|
||||
clip.x = (tile_map_[INDEX] % tile_set_width_) * TILE_SIZE_;
|
||||
clip.y = (tile_map_[INDEX] / tile_set_width_) * TILE_SIZE_;
|
||||
surface_->render(x * TILE_SIZE_, y * TILE_SIZE_, &clip);
|
||||
clip.x = (tile_map_[INDEX] % tile_set_width_) * TILE_SIZE;
|
||||
clip.y = (tile_map_[INDEX] / tile_set_width_) * TILE_SIZE;
|
||||
surface_->render(x * TILE_SIZE, y * TILE_SIZE, &clip);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
if (Debug::get()->getEnabled()) {
|
||||
@@ -517,23 +519,23 @@ std::string Room::getRoom(RoomBorder border) {
|
||||
|
||||
// Devuelve el tipo de tile que hay en ese pixel
|
||||
TileType Room::getTile(SDL_FPoint point) {
|
||||
const int pos = ((point.y / TILE_SIZE_) * MAP_WIDTH_) + (point.x / TILE_SIZE_);
|
||||
return getTile(pos);
|
||||
const int POS = ((point.y / TILE_SIZE) * MAP_WIDTH) + (point.x / TILE_SIZE);
|
||||
return getTile(POS);
|
||||
}
|
||||
|
||||
// Devuelve el tipo de tile que hay en ese indice
|
||||
TileType Room::getTile(int index) {
|
||||
// const bool onRange = (index > -1) && (index < mapWidth * mapHeight);
|
||||
const bool onRange = (index > -1) && (index < (int)tile_map_.size());
|
||||
const bool ON_RANGE = (index > -1) && (index < (int)tile_map_.size());
|
||||
|
||||
if (onRange) {
|
||||
if (ON_RANGE) {
|
||||
// Las filas 0-8 son de tiles t_wall
|
||||
if ((tile_map_[index] >= 0) && (tile_map_[index] < 9 * tile_set_width_)) {
|
||||
return TileType::WALL;
|
||||
}
|
||||
|
||||
// Las filas 9-17 son de tiles t_passable
|
||||
else if ((tile_map_[index] >= 9 * tile_set_width_) && (tile_map_[index] < 18 * tile_set_width_)) {
|
||||
if ((tile_map_[index] >= 9 * tile_set_width_) && (tile_map_[index] < 18 * tile_set_width_)) {
|
||||
return TileType::PASSABLE;
|
||||
}
|
||||
|
||||
@@ -590,25 +592,25 @@ bool Room::itemCollision(SDL_FRect& rect) {
|
||||
// Obten la coordenada de la cuesta a partir de un punto perteneciente a ese tile
|
||||
int Room::getSlopeHeight(SDL_FPoint p, TileType slope) {
|
||||
// Calcula la base del tile
|
||||
int base = ((p.y / TILE_SIZE_) * TILE_SIZE_) + TILE_SIZE_;
|
||||
int base = ((p.y / TILE_SIZE) * TILE_SIZE) + TILE_SIZE;
|
||||
#ifdef _DEBUG
|
||||
Debug::get()->add("BASE = " + std::to_string(base));
|
||||
#endif
|
||||
|
||||
// Calcula cuanto se ha entrado en el tile horizontalmente
|
||||
const int pos = (static_cast<int>(p.x) % TILE_SIZE_); // Esto da un valor entre 0 y 7
|
||||
const int POS = (static_cast<int>(p.x) % TILE_SIZE); // Esto da un valor entre 0 y 7
|
||||
#ifdef _DEBUG
|
||||
Debug::get()->add("POS = " + std::to_string(pos));
|
||||
Debug::get()->add("POS = " + std::to_string(POS));
|
||||
#endif
|
||||
|
||||
// Se resta a la base la cantidad de pixeles pos en funcion de la rampa
|
||||
if (slope == TileType::SLOPE_R) {
|
||||
base -= pos + 1;
|
||||
base -= POS + 1;
|
||||
#ifdef _DEBUG
|
||||
Debug::get()->add("BASE_R = " + std::to_string(base));
|
||||
#endif
|
||||
} else {
|
||||
base -= (TILE_SIZE_ - pos);
|
||||
base -= (TILE_SIZE - POS);
|
||||
#ifdef _DEBUG
|
||||
Debug::get()->add("BASE_L = " + std::to_string(base));
|
||||
#endif
|
||||
@@ -623,12 +625,12 @@ void Room::setBottomSurfaces() {
|
||||
|
||||
// Busca todos los tiles de tipo muro que no tengan debajo otro muro
|
||||
// Hay que recorrer la habitación por filas (excepto los de la última fila)
|
||||
for (int i = 0; i < (int)tile_map_.size() - MAP_WIDTH_; ++i) {
|
||||
if (getTile(i) == TileType::WALL && getTile(i + MAP_WIDTH_) != TileType::WALL) {
|
||||
for (int i = 0; i < (int)tile_map_.size() - MAP_WIDTH; ++i) {
|
||||
if (getTile(i) == TileType::WALL && getTile(i + MAP_WIDTH) != TileType::WALL) {
|
||||
tile.push_back(i);
|
||||
|
||||
// Si llega al final de la fila, introduce un separador
|
||||
if (i % MAP_WIDTH_ == MAP_WIDTH_ - 1) {
|
||||
if (i % MAP_WIDTH == MAP_WIDTH - 1) {
|
||||
tile.push_back(-1);
|
||||
}
|
||||
}
|
||||
@@ -642,8 +644,8 @@ void Room::setBottomSurfaces() {
|
||||
int i = 0;
|
||||
do {
|
||||
LineHorizontal line;
|
||||
line.x1 = (tile[i] % MAP_WIDTH_) * TILE_SIZE_;
|
||||
line.y = ((tile[i] / MAP_WIDTH_) * TILE_SIZE_) + TILE_SIZE_ - 1;
|
||||
line.x1 = (tile[i] % MAP_WIDTH) * TILE_SIZE;
|
||||
line.y = ((tile[i] / MAP_WIDTH) * TILE_SIZE) + TILE_SIZE - 1;
|
||||
int last_one = i;
|
||||
i++;
|
||||
|
||||
@@ -657,7 +659,7 @@ void Room::setBottomSurfaces() {
|
||||
}
|
||||
}
|
||||
|
||||
line.x2 = ((tile[last_one] % MAP_WIDTH_) * TILE_SIZE_) + TILE_SIZE_ - 1;
|
||||
line.x2 = ((tile[last_one] % MAP_WIDTH) * TILE_SIZE) + TILE_SIZE - 1;
|
||||
bottom_floors_.push_back(line);
|
||||
if (i <= (int)tile.size() - 1) {
|
||||
if (tile[i] == -1) { // Si el siguiente elemento es un separador, hay que saltarlo
|
||||
@@ -674,12 +676,12 @@ void Room::setTopSurfaces() {
|
||||
|
||||
// Busca todos los tiles de tipo muro o pasable que no tengan encima un muro
|
||||
// Hay que recorrer la habitación por filas (excepto los de la primera fila)
|
||||
for (int i = MAP_WIDTH_; i < (int)tile_map_.size(); ++i) {
|
||||
if ((getTile(i) == TileType::WALL || getTile(i) == TileType::PASSABLE) && getTile(i - MAP_WIDTH_) != TileType::WALL) {
|
||||
for (int i = MAP_WIDTH; i < (int)tile_map_.size(); ++i) {
|
||||
if ((getTile(i) == TileType::WALL || getTile(i) == TileType::PASSABLE) && getTile(i - MAP_WIDTH) != TileType::WALL) {
|
||||
tile.push_back(i);
|
||||
|
||||
// Si llega al final de la fila, introduce un separador
|
||||
if (i % MAP_WIDTH_ == MAP_WIDTH_ - 1) {
|
||||
if (i % MAP_WIDTH == MAP_WIDTH - 1) {
|
||||
tile.push_back(-1);
|
||||
}
|
||||
}
|
||||
@@ -693,8 +695,8 @@ void Room::setTopSurfaces() {
|
||||
int i = 0;
|
||||
do {
|
||||
LineHorizontal line;
|
||||
line.x1 = (tile[i] % MAP_WIDTH_) * TILE_SIZE_;
|
||||
line.y = (tile[i] / MAP_WIDTH_) * TILE_SIZE_;
|
||||
line.x1 = (tile[i] % MAP_WIDTH) * TILE_SIZE;
|
||||
line.y = (tile[i] / MAP_WIDTH) * TILE_SIZE;
|
||||
int last_one = i;
|
||||
i++;
|
||||
|
||||
@@ -708,7 +710,7 @@ void Room::setTopSurfaces() {
|
||||
}
|
||||
}
|
||||
|
||||
line.x2 = ((tile[last_one] % MAP_WIDTH_) * TILE_SIZE_) + TILE_SIZE_ - 1;
|
||||
line.x2 = ((tile[last_one] % MAP_WIDTH) * TILE_SIZE) + TILE_SIZE - 1;
|
||||
top_floors_.push_back(line);
|
||||
if (i <= (int)tile.size() - 1) {
|
||||
if (tile[i] == -1) { // Si el siguiente elemento es un separador, hay que saltarlo
|
||||
@@ -725,11 +727,11 @@ void Room::setLeftSurfaces() {
|
||||
|
||||
// Busca todos los tiles de tipo muro que no tienen a su izquierda un tile de tipo muro
|
||||
// Hay que recorrer la habitación por columnas (excepto los de la primera columna)
|
||||
for (int i = 1; i < MAP_WIDTH_; ++i) {
|
||||
for (int j = 0; j < MAP_HEIGHT_; ++j) {
|
||||
const int pos = (j * MAP_WIDTH_ + i);
|
||||
if (getTile(pos) == TileType::WALL && getTile(pos - 1) != TileType::WALL) {
|
||||
tile.push_back(pos);
|
||||
for (int i = 1; i < MAP_WIDTH; ++i) {
|
||||
for (int j = 0; j < MAP_HEIGHT; ++j) {
|
||||
const int POS = ((j * MAP_WIDTH) + i);
|
||||
if (getTile(POS) == TileType::WALL && getTile(POS - 1) != TileType::WALL) {
|
||||
tile.push_back(POS);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -744,15 +746,15 @@ void Room::setLeftSurfaces() {
|
||||
int i = 0;
|
||||
do {
|
||||
LineVertical line;
|
||||
line.x = (tile[i] % MAP_WIDTH_) * TILE_SIZE_;
|
||||
line.y1 = ((tile[i] / MAP_WIDTH_) * TILE_SIZE_);
|
||||
while (tile[i] + MAP_WIDTH_ == tile[i + 1]) {
|
||||
line.x = (tile[i] % MAP_WIDTH) * TILE_SIZE;
|
||||
line.y1 = ((tile[i] / MAP_WIDTH) * TILE_SIZE);
|
||||
while (tile[i] + MAP_WIDTH == tile[i + 1]) {
|
||||
if (i == (int)tile.size() - 1) {
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
line.y2 = ((tile[i] / MAP_WIDTH_) * TILE_SIZE_) + TILE_SIZE_ - 1;
|
||||
line.y2 = ((tile[i] / MAP_WIDTH) * TILE_SIZE) + TILE_SIZE - 1;
|
||||
left_walls_.push_back(line);
|
||||
i++;
|
||||
} while (i < (int)tile.size() - 1);
|
||||
@@ -765,11 +767,11 @@ void Room::setRightSurfaces() {
|
||||
|
||||
// Busca todos los tiles de tipo muro que no tienen a su derecha un tile de tipo muro
|
||||
// Hay que recorrer la habitación por columnas (excepto los de la última columna)
|
||||
for (int i = 0; i < MAP_WIDTH_ - 1; ++i) {
|
||||
for (int j = 0; j < MAP_HEIGHT_; ++j) {
|
||||
const int pos = (j * MAP_WIDTH_ + i);
|
||||
if (getTile(pos) == TileType::WALL && getTile(pos + 1) != TileType::WALL) {
|
||||
tile.push_back(pos);
|
||||
for (int i = 0; i < MAP_WIDTH - 1; ++i) {
|
||||
for (int j = 0; j < MAP_HEIGHT; ++j) {
|
||||
const int POS = ((j * MAP_WIDTH) + i);
|
||||
if (getTile(POS) == TileType::WALL && getTile(POS + 1) != TileType::WALL) {
|
||||
tile.push_back(POS);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -784,15 +786,15 @@ void Room::setRightSurfaces() {
|
||||
int i = 0;
|
||||
do {
|
||||
LineVertical line;
|
||||
line.x = ((tile[i] % MAP_WIDTH_) * TILE_SIZE_) + TILE_SIZE_ - 1;
|
||||
line.y1 = ((tile[i] / MAP_WIDTH_) * TILE_SIZE_);
|
||||
while (tile[i] + MAP_WIDTH_ == tile[i + 1]) {
|
||||
line.x = ((tile[i] % MAP_WIDTH) * TILE_SIZE) + TILE_SIZE - 1;
|
||||
line.y1 = ((tile[i] / MAP_WIDTH) * TILE_SIZE);
|
||||
while (tile[i] + MAP_WIDTH == tile[i + 1]) {
|
||||
if (i == (int)tile.size() - 1) {
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
line.y2 = ((tile[i] / MAP_WIDTH_) * TILE_SIZE_) + TILE_SIZE_ - 1;
|
||||
line.y2 = ((tile[i] / MAP_WIDTH) * TILE_SIZE) + TILE_SIZE - 1;
|
||||
right_walls_.push_back(line);
|
||||
i++;
|
||||
} while (i < (int)tile.size() - 1);
|
||||
@@ -813,23 +815,23 @@ void Room::setLeftSlopes() {
|
||||
// que seran i + mapWidth + 1. Conforme se añaden se eliminan y se vuelve a escudriñar el vector de
|
||||
// tiles encontrados hasta que esté vacío
|
||||
|
||||
while (found.size() > 0) {
|
||||
while (!found.empty()) {
|
||||
LineDiagonal line;
|
||||
line.x1 = (found[0] % MAP_WIDTH_) * TILE_SIZE_;
|
||||
line.y1 = (found[0] / MAP_WIDTH_) * TILE_SIZE_;
|
||||
int lookingFor = found[0] + MAP_WIDTH_ + 1;
|
||||
int lastOneFound = found[0];
|
||||
line.x1 = (found[0] % MAP_WIDTH) * TILE_SIZE;
|
||||
line.y1 = (found[0] / MAP_WIDTH) * TILE_SIZE;
|
||||
int looking_for = found[0] + MAP_WIDTH + 1;
|
||||
int last_one_found = found[0];
|
||||
found.erase(found.begin());
|
||||
for (int i = 0; i < (int)found.size(); ++i) {
|
||||
if (found[i] == lookingFor) {
|
||||
lastOneFound = lookingFor;
|
||||
lookingFor += MAP_WIDTH_ + 1;
|
||||
if (found[i] == looking_for) {
|
||||
last_one_found = looking_for;
|
||||
looking_for += MAP_WIDTH + 1;
|
||||
found.erase(found.begin() + i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
line.x2 = ((lastOneFound % MAP_WIDTH_) * TILE_SIZE_) + TILE_SIZE_ - 1;
|
||||
line.y2 = ((lastOneFound / MAP_WIDTH_) * TILE_SIZE_) + TILE_SIZE_ - 1;
|
||||
line.x2 = ((last_one_found % MAP_WIDTH) * TILE_SIZE) + TILE_SIZE - 1;
|
||||
line.y2 = ((last_one_found / MAP_WIDTH) * TILE_SIZE) + TILE_SIZE - 1;
|
||||
left_slopes_.push_back(line);
|
||||
}
|
||||
}
|
||||
@@ -848,23 +850,23 @@ void Room::setRightSlopes() {
|
||||
// que seran i + mapWidth - 1. Conforme se añaden se eliminan y se vuelve a escudriñar el vector de
|
||||
// tiles encontrados hasta que esté vacío
|
||||
|
||||
while (found.size() > 0) {
|
||||
while (!found.empty()) {
|
||||
LineDiagonal line;
|
||||
line.x1 = ((found[0] % MAP_WIDTH_) * TILE_SIZE_) + TILE_SIZE_ - 1;
|
||||
line.y1 = (found[0] / MAP_WIDTH_) * TILE_SIZE_;
|
||||
int lookingFor = found[0] + MAP_WIDTH_ - 1;
|
||||
int lastOneFound = found[0];
|
||||
line.x1 = ((found[0] % MAP_WIDTH) * TILE_SIZE) + TILE_SIZE - 1;
|
||||
line.y1 = (found[0] / MAP_WIDTH) * TILE_SIZE;
|
||||
int looking_for = found[0] + MAP_WIDTH - 1;
|
||||
int last_one_found = found[0];
|
||||
found.erase(found.begin());
|
||||
for (int i = 0; i < (int)found.size(); ++i) {
|
||||
if (found[i] == lookingFor) {
|
||||
lastOneFound = lookingFor;
|
||||
lookingFor += MAP_WIDTH_ - 1;
|
||||
if (found[i] == looking_for) {
|
||||
last_one_found = looking_for;
|
||||
looking_for += MAP_WIDTH - 1;
|
||||
found.erase(found.begin() + i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
line.x2 = (lastOneFound % MAP_WIDTH_) * TILE_SIZE_;
|
||||
line.y2 = ((lastOneFound / MAP_WIDTH_) * TILE_SIZE_) + TILE_SIZE_ - 1;
|
||||
line.x2 = (last_one_found % MAP_WIDTH) * TILE_SIZE;
|
||||
line.y2 = ((last_one_found / MAP_WIDTH) * TILE_SIZE) + TILE_SIZE - 1;
|
||||
right_slopes_.push_back(line);
|
||||
}
|
||||
}
|
||||
@@ -875,12 +877,12 @@ void Room::setAutoSurfaces() {
|
||||
|
||||
// Busca todos los tiles de tipo animado
|
||||
// Hay que recorrer la habitación por filas (excepto los de la primera fila)
|
||||
for (int i = MAP_WIDTH_; i < (int)tile_map_.size(); ++i) {
|
||||
for (int i = MAP_WIDTH; i < (int)tile_map_.size(); ++i) {
|
||||
if (getTile(i) == TileType::ANIMATED) {
|
||||
tile.push_back(i);
|
||||
|
||||
// Si llega al final de la fila, introduce un separador
|
||||
if (i % MAP_WIDTH_ == MAP_WIDTH_ - 1) {
|
||||
if (i % MAP_WIDTH == MAP_WIDTH - 1) {
|
||||
tile.push_back(-1);
|
||||
}
|
||||
}
|
||||
@@ -891,8 +893,8 @@ void Room::setAutoSurfaces() {
|
||||
int i = 0;
|
||||
do {
|
||||
LineHorizontal line;
|
||||
line.x1 = (tile[i] % MAP_WIDTH_) * TILE_SIZE_;
|
||||
line.y = (tile[i] / MAP_WIDTH_) * TILE_SIZE_;
|
||||
line.x1 = (tile[i] % MAP_WIDTH) * TILE_SIZE;
|
||||
line.y = (tile[i] / MAP_WIDTH) * TILE_SIZE;
|
||||
int last_one = i;
|
||||
i++;
|
||||
|
||||
@@ -906,7 +908,7 @@ void Room::setAutoSurfaces() {
|
||||
}
|
||||
}
|
||||
|
||||
line.x2 = ((tile[last_one] % MAP_WIDTH_) * TILE_SIZE_) + TILE_SIZE_ - 1;
|
||||
line.x2 = ((tile[last_one] % MAP_WIDTH) * TILE_SIZE) + TILE_SIZE - 1;
|
||||
conveyor_belt_floors_.push_back(line);
|
||||
if (i <= (int)tile.size() - 1) {
|
||||
if (tile[i] == -1) { // Si el siguiente elemento es un separador, hay que saltarlo
|
||||
@@ -923,17 +925,17 @@ void Room::setAnimatedTiles() {
|
||||
for (int i = 0; i < (int)tile_map_.size(); ++i) {
|
||||
if (getTile(i) == TileType::ANIMATED) {
|
||||
// La i es la ubicación
|
||||
const int x = (i % MAP_WIDTH_) * TILE_SIZE_;
|
||||
const int y = (i / MAP_WIDTH_) * TILE_SIZE_;
|
||||
const int X = (i % MAP_WIDTH) * TILE_SIZE;
|
||||
const int Y = (i / MAP_WIDTH) * TILE_SIZE;
|
||||
|
||||
// TileMap[i] es el tile a poner
|
||||
const int xc = (tile_map_[i] % tile_set_width_) * TILE_SIZE_;
|
||||
const int yc = (tile_map_[i] / tile_set_width_) * TILE_SIZE_;
|
||||
const int XC = (tile_map_[i] % tile_set_width_) * TILE_SIZE;
|
||||
const int YC = (tile_map_[i] / tile_set_width_) * TILE_SIZE;
|
||||
|
||||
AnimatedTile at;
|
||||
at.sprite = std::make_shared<SurfaceSprite>(surface_, x, y, 8, 8);
|
||||
at.sprite->setClip(xc, yc, 8, 8);
|
||||
at.x_orig = xc;
|
||||
at.sprite = std::make_shared<SurfaceSprite>(surface_, X, Y, 8, 8);
|
||||
at.sprite->setClip(XC, YC, 8, 8);
|
||||
at.x_orig = XC;
|
||||
animated_tiles_.push_back(at);
|
||||
}
|
||||
}
|
||||
@@ -941,12 +943,12 @@ void Room::setAnimatedTiles() {
|
||||
|
||||
// Actualiza los tiles animados
|
||||
void Room::updateAnimatedTiles() {
|
||||
const int numFrames = 4;
|
||||
const int NUM_FRAMES = 4;
|
||||
int offset = 0;
|
||||
if (conveyor_belt_direction_ == -1) {
|
||||
offset = ((counter_ / 3) % numFrames * TILE_SIZE_);
|
||||
offset = ((counter_ / 3) % NUM_FRAMES * TILE_SIZE);
|
||||
} else {
|
||||
offset = ((numFrames - 1 - ((counter_ / 3) % numFrames)) * TILE_SIZE_);
|
||||
offset = ((NUM_FRAMES - 1 - ((counter_ / 3) % NUM_FRAMES)) * TILE_SIZE);
|
||||
}
|
||||
|
||||
for (auto& a : animated_tiles_) {
|
||||
@@ -1043,9 +1045,9 @@ bool Room::checkAutoSurfaces(SDL_FPoint* p) {
|
||||
// Comprueba las colisiones
|
||||
int Room::checkLeftSlopes(const LineVertical* line) {
|
||||
for (const auto& slope : left_slopes_) {
|
||||
const auto p = checkCollision(slope, *line);
|
||||
if (p.x != -1) {
|
||||
return p.y;
|
||||
const auto P = checkCollision(slope, *line);
|
||||
if (P.x != -1) {
|
||||
return P.y;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1066,9 +1068,9 @@ bool Room::checkLeftSlopes(SDL_FPoint* p) {
|
||||
// Comprueba las colisiones
|
||||
int Room::checkRightSlopes(const LineVertical* line) {
|
||||
for (const auto& slope : right_slopes_) {
|
||||
const auto p = checkCollision(slope, *line);
|
||||
if (p.x != -1) {
|
||||
return p.y;
|
||||
const auto P = checkCollision(slope, *line);
|
||||
if (P.x != -1) {
|
||||
return P.y;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -72,9 +72,9 @@ bool setItem(ItemData* item, const std::string& key, const std::string& value);
|
||||
class Room {
|
||||
private:
|
||||
// Constantes
|
||||
static constexpr int TILE_SIZE_ = 8; // Ancho del tile en pixels
|
||||
static constexpr int MAP_WIDTH_ = 32; // Ancho del mapa en tiles
|
||||
static constexpr int MAP_HEIGHT_ = 16; // Alto del mapa en tiles
|
||||
static constexpr int TILE_SIZE = 8; // Ancho del tile en pixels
|
||||
static constexpr int MAP_WIDTH = 32; // Ancho del mapa en tiles
|
||||
static constexpr int MAP_HEIGHT = 16; // Alto del mapa en tiles
|
||||
|
||||
// Objetos y punteros
|
||||
std::vector<std::shared_ptr<Enemy>> enemies_; // Listado con los enemigos de la habitación
|
||||
@@ -195,10 +195,10 @@ class Room {
|
||||
bool itemCollision(SDL_FRect& rect);
|
||||
|
||||
// Obten el tamaño del tile
|
||||
int getTileSize() const { return TILE_SIZE_; }
|
||||
static int getTileSize() { return TILE_SIZE; }
|
||||
|
||||
// Obten la coordenada de la cuesta a partir de un punto perteneciente a ese tile
|
||||
int getSlopeHeight(SDL_FPoint p, TileType slope);
|
||||
static int getSlopeHeight(SDL_FPoint p, TileType slope);
|
||||
|
||||
// Comprueba las colisiones
|
||||
int checkRightSurfaces(SDL_FRect* rect);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
// Comprueba si la habitación ya ha sido visitada
|
||||
bool RoomTracker::hasBeenVisited(const std::string& name) {
|
||||
for (const auto& l : list) {
|
||||
for (const auto& l : list_) {
|
||||
if (l == name) {
|
||||
return true;
|
||||
}
|
||||
@@ -16,7 +16,7 @@ bool RoomTracker::addRoom(const std::string& name) {
|
||||
// Comprueba si la habitación ya ha sido visitada
|
||||
if (!hasBeenVisited(name)) {
|
||||
// En caso contrario añádela a la lista
|
||||
list.push_back(name);
|
||||
list_.push_back(name);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
class RoomTracker {
|
||||
private:
|
||||
// Variables
|
||||
std::vector<std::string> list; // Lista con las habitaciones visitadas
|
||||
std::vector<std::string> list_; // Lista con las habitaciones visitadas
|
||||
|
||||
// Comprueba si la habitación ya ha sido visitada
|
||||
bool hasBeenVisited(const std::string& name);
|
||||
|
||||
@@ -14,10 +14,9 @@
|
||||
// Constructor
|
||||
Scoreboard::Scoreboard(std::shared_ptr<ScoreboardData> data)
|
||||
: item_surface_(Resource::get()->getSurface("items.gif")),
|
||||
data_(data),
|
||||
clock_(ClockData()) {
|
||||
const float SURFACE_WIDTH_ = Options::game.width;
|
||||
constexpr float SURFACE_HEIGHT_ = 6.0F * BLOCK;
|
||||
data_(data) {
|
||||
const float SURFACE_WIDTH = Options::game.width;
|
||||
constexpr float SURFACE_HEIGHT = 6.0F * BLOCK;
|
||||
|
||||
// Reserva memoria para los objetos
|
||||
auto player_texture = Resource::get()->getSurface(Options::cheats.alternate_skin == Options::Cheat::State::ENABLED ? "player2.gif" : "player.gif");
|
||||
@@ -25,8 +24,8 @@ Scoreboard::Scoreboard(std::shared_ptr<ScoreboardData> data)
|
||||
player_sprite_ = std::make_shared<SurfaceAnimatedSprite>(player_texture, player_animations);
|
||||
player_sprite_->setCurrentAnimation("walk_menu");
|
||||
|
||||
surface_ = std::make_shared<Surface>(SURFACE_WIDTH_, SURFACE_HEIGHT_);
|
||||
surface_dest_ = {0, Options::game.height - SURFACE_HEIGHT_, SURFACE_WIDTH_, SURFACE_HEIGHT_};
|
||||
surface_ = std::make_shared<Surface>(SURFACE_WIDTH, SURFACE_HEIGHT);
|
||||
surface_dest_ = {0, Options::game.height - SURFACE_HEIGHT, SURFACE_WIDTH, SURFACE_HEIGHT};
|
||||
|
||||
// Inicializa las variables
|
||||
counter_ = 0;
|
||||
@@ -67,13 +66,13 @@ void Scoreboard::update() {
|
||||
|
||||
// Obtiene el tiempo transcurrido de partida
|
||||
Scoreboard::ClockData Scoreboard::getTime() {
|
||||
const Uint32 timeElapsed = SDL_GetTicks() - data_->ini_clock - paused_time_elapsed_;
|
||||
const Uint32 TIME_ELAPSED = SDL_GetTicks() - data_->ini_clock - paused_time_elapsed_;
|
||||
|
||||
ClockData time;
|
||||
time.hours = timeElapsed / 3600000;
|
||||
time.minutes = timeElapsed / 60000;
|
||||
time.seconds = timeElapsed / 1000;
|
||||
time.separator = (timeElapsed % 1000 <= 500) ? ":" : " ";
|
||||
time.hours = TIME_ELAPSED / 3600000;
|
||||
time.minutes = TIME_ELAPSED / 60000;
|
||||
time.seconds = TIME_ELAPSED / 1000;
|
||||
time.separator = (TIME_ELAPSED % 1000 <= 500) ? ":" : " ";
|
||||
|
||||
return time;
|
||||
}
|
||||
@@ -128,21 +127,21 @@ void Scoreboard::fillTexture() {
|
||||
constexpr int LINE2 = 3 * BLOCK;
|
||||
|
||||
// Dibuja las vidas
|
||||
const int desp = (counter_ / 40) % 8;
|
||||
const int frame = desp % 4;
|
||||
player_sprite_->setCurrentAnimationFrame(frame);
|
||||
const int DESP = (counter_ / 40) % 8;
|
||||
const int FRAME = DESP % 4;
|
||||
player_sprite_->setCurrentAnimationFrame(FRAME);
|
||||
player_sprite_->setPosY(LINE2);
|
||||
for (int i = 0; i < data_->lives; ++i) {
|
||||
player_sprite_->setPosX(8 + (16 * i) + desp);
|
||||
const int index = i % color_.size();
|
||||
player_sprite_->render(1, color_.at(index));
|
||||
player_sprite_->setPosX(8 + (16 * i) + DESP);
|
||||
const int INDEX = i % color_.size();
|
||||
player_sprite_->render(1, color_.at(INDEX));
|
||||
}
|
||||
|
||||
// Muestra si suena la música
|
||||
if (data_->music) {
|
||||
const Uint8 c = data_->color;
|
||||
const Uint8 C = data_->color;
|
||||
SDL_FRect clip = {0, 8, 8, 8};
|
||||
item_surface_->renderWithColorReplace(20 * BLOCK, LINE2, 1, c, &clip);
|
||||
item_surface_->renderWithColorReplace(20 * BLOCK, LINE2, 1, C, &clip);
|
||||
}
|
||||
|
||||
// Escribe los textos
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
|
||||
// Constructor
|
||||
Stats::Stats(const std::string& file, const std::string& buffer)
|
||||
: bufferPath(buffer),
|
||||
filePath(file) {}
|
||||
: buffer_path_(buffer),
|
||||
file_path_(file) {}
|
||||
|
||||
// Destructor
|
||||
Stats::~Stats() {
|
||||
@@ -19,20 +19,20 @@ Stats::~Stats() {
|
||||
checkWorstNightmare();
|
||||
|
||||
// Guarda las estadísticas
|
||||
saveToFile(bufferPath, bufferList);
|
||||
saveToFile(filePath, list);
|
||||
saveToFile(buffer_path_, buffer_list_);
|
||||
saveToFile(file_path_, list_);
|
||||
|
||||
bufferList.clear();
|
||||
list.clear();
|
||||
dictionary.clear();
|
||||
buffer_list_.clear();
|
||||
list_.clear();
|
||||
dictionary_.clear();
|
||||
}
|
||||
|
||||
// Inicializador
|
||||
void Stats::init()
|
||||
// Se debe llamar a este procedimiento una vez se haya creado el diccionario numero-nombre
|
||||
{
|
||||
loadFromFile(bufferPath, bufferList);
|
||||
loadFromFile(filePath, list);
|
||||
loadFromFile(buffer_path_, buffer_list_);
|
||||
loadFromFile(file_path_, list_);
|
||||
|
||||
// Vuelca los datos del buffer en la lista de estadisticas
|
||||
updateListFromBuffer();
|
||||
@@ -41,9 +41,9 @@ void Stats::init()
|
||||
// Añade una muerte a las estadisticas
|
||||
void Stats::addDeath(const std::string& name) {
|
||||
// Primero busca si ya hay una entrada con ese nombre
|
||||
const int index = findByName(name, bufferList);
|
||||
if (index != -1) {
|
||||
bufferList[index].died++;
|
||||
const int INDEX = findByName(name, buffer_list_);
|
||||
if (INDEX != -1) {
|
||||
buffer_list_[INDEX].died++;
|
||||
}
|
||||
|
||||
// En caso contrario crea la entrada
|
||||
@@ -52,16 +52,16 @@ void Stats::addDeath(const std::string& name) {
|
||||
item.name = name;
|
||||
item.visited = 0;
|
||||
item.died = 1;
|
||||
bufferList.push_back(item);
|
||||
buffer_list_.push_back(item);
|
||||
}
|
||||
}
|
||||
|
||||
// Añade una visita a las estadisticas
|
||||
void Stats::addVisit(const std::string& name) {
|
||||
// Primero busca si ya hay una entrada con ese nombre
|
||||
const int index = findByName(name, bufferList);
|
||||
if (index != -1) {
|
||||
bufferList[index].visited++;
|
||||
const int INDEX = findByName(name, buffer_list_);
|
||||
if (INDEX != -1) {
|
||||
buffer_list_[INDEX].visited++;
|
||||
}
|
||||
|
||||
// En caso contrario crea la entrada
|
||||
@@ -70,15 +70,15 @@ void Stats::addVisit(const std::string& name) {
|
||||
item.name = name;
|
||||
item.visited = 1;
|
||||
item.died = 0;
|
||||
bufferList.push_back(item);
|
||||
buffer_list_.push_back(item);
|
||||
}
|
||||
}
|
||||
|
||||
// Busca una entrada en la lista por nombre
|
||||
int Stats::findByName(const std::string& name, const std::vector<StatsData>& list) {
|
||||
int Stats::findByName(const std::string& name, const std::vector<StatsData>& list_) {
|
||||
int i = 0;
|
||||
|
||||
for (const auto& l : list) {
|
||||
for (const auto& l : list_) {
|
||||
if (l.name == name) {
|
||||
return i;
|
||||
}
|
||||
@@ -89,8 +89,8 @@ int Stats::findByName(const std::string& name, const std::vector<StatsData>& lis
|
||||
}
|
||||
|
||||
// Carga las estadisticas desde un fichero
|
||||
bool Stats::loadFromFile(const std::string& file_path, std::vector<StatsData>& list) {
|
||||
list.clear();
|
||||
bool Stats::loadFromFile(const std::string& file_path, std::vector<StatsData>& list_) {
|
||||
list_.clear();
|
||||
|
||||
// Indicador de éxito en la carga
|
||||
bool success = true;
|
||||
@@ -121,7 +121,7 @@ bool Stats::loadFromFile(const std::string& file_path, std::vector<StatsData>& l
|
||||
getline(ss, tmp, ';');
|
||||
stat.died = std::stoi(tmp);
|
||||
|
||||
list.push_back(stat);
|
||||
list_.push_back(stat);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,20 +132,20 @@ bool Stats::loadFromFile(const std::string& file_path, std::vector<StatsData>& l
|
||||
// El fichero no existe
|
||||
else {
|
||||
// Crea el fichero con los valores por defecto
|
||||
saveToFile(file_path, list);
|
||||
saveToFile(file_path, list_);
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
// 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<StatsData>& list_) {
|
||||
// Crea y abre el fichero de texto
|
||||
std::ofstream file(file_path);
|
||||
|
||||
// Escribe en el fichero
|
||||
file << "# ROOM NAME;VISITS;DEATHS" << std::endl;
|
||||
for (const auto& item : list) {
|
||||
for (const auto& item : list_) {
|
||||
file << item.name << ";" << item.visited << ";" << item.died << std::endl;
|
||||
}
|
||||
|
||||
@@ -156,7 +156,7 @@ void Stats::saveToFile(const std::string& file_path, const std::vector<StatsData
|
||||
// Calcula cual es la habitación con más muertes
|
||||
void Stats::checkWorstNightmare() {
|
||||
int deaths = 0;
|
||||
for (const auto& item : list) {
|
||||
for (const auto& item : list_) {
|
||||
if (item.died > deaths) {
|
||||
deaths = item.died;
|
||||
Options::stats.worst_nightmare = item.name;
|
||||
@@ -166,27 +166,27 @@ void Stats::checkWorstNightmare() {
|
||||
|
||||
// Añade una entrada al diccionario
|
||||
void Stats::addDictionary(const std::string& number, const std::string& name) {
|
||||
dictionary.push_back({number, name});
|
||||
dictionary_.push_back({number, name});
|
||||
}
|
||||
|
||||
// Vuelca los datos del buffer en la lista de estadisticas
|
||||
void Stats::updateListFromBuffer() {
|
||||
// Actualiza list desde bufferList
|
||||
for (const auto& buffer : bufferList) {
|
||||
int index = findByName(buffer.name, list);
|
||||
// Actualiza list_ desde buffer_list_
|
||||
for (const auto& buffer : buffer_list_) {
|
||||
int index = findByName(buffer.name, list_);
|
||||
|
||||
if (index != -1) { // Encontrado. Aumenta sus estadisticas
|
||||
list[index].visited += buffer.visited;
|
||||
list[index].died += buffer.died;
|
||||
list_[index].visited += buffer.visited;
|
||||
list_[index].died += buffer.died;
|
||||
} else { // En caso contrario crea la entrada
|
||||
StatsData item;
|
||||
item.name = buffer.name;
|
||||
item.visited = buffer.visited;
|
||||
item.died = buffer.died;
|
||||
list.push_back(item);
|
||||
list_.push_back(item);
|
||||
}
|
||||
}
|
||||
|
||||
saveToFile(bufferPath, bufferList);
|
||||
saveToFile(filePath, list);
|
||||
saveToFile(buffer_path_, buffer_list_);
|
||||
saveToFile(file_path_, list_);
|
||||
}
|
||||
@@ -17,20 +17,20 @@ class Stats {
|
||||
};
|
||||
|
||||
// Variables
|
||||
std::vector<StatsDictionary> dictionary; // Lista con la equivalencia nombre-numero de habitacion
|
||||
std::vector<StatsData> bufferList; // Lista con las estadisticas temporales por habitación
|
||||
std::vector<StatsData> list; // Lista con las estadisticas completas por habitación
|
||||
std::string bufferPath; // Fichero con las estadísticas temporales
|
||||
std::string filePath; // Fichero con las estadísticas completas
|
||||
std::vector<StatsDictionary> dictionary_; // Lista con la equivalencia nombre-numero de habitacion
|
||||
std::vector<StatsData> buffer_list_; // Lista con las estadisticas temporales por habitación
|
||||
std::vector<StatsData> list_; // Lista con las estadisticas completas por habitación
|
||||
std::string buffer_path_; // Fichero con las estadísticas temporales
|
||||
std::string file_path_; // Fichero con las estadísticas completas
|
||||
|
||||
// Busca una entrada en la lista por nombre
|
||||
int findByName(const std::string& name, const std::vector<StatsData>& list);
|
||||
static int findByName(const std::string& name, const std::vector<StatsData>& list);
|
||||
|
||||
// Carga las estadisticas desde un fichero
|
||||
bool loadFromFile(const std::string& filePath, std::vector<StatsData>& list);
|
||||
bool loadFromFile(const std::string& file_path, std::vector<StatsData>& list);
|
||||
|
||||
// Guarda las estadisticas en un fichero
|
||||
void saveToFile(const std::string& filePath, const std::vector<StatsData>& list);
|
||||
static void saveToFile(const std::string& file_path, const std::vector<StatsData>& list);
|
||||
|
||||
// Calcula cual es la habitación con más muertes
|
||||
void checkWorstNightmare();
|
||||
|
||||
Reference in New Issue
Block a user