Varios arreglos d'estil en el codi i llevar metodes que ja no servien
This commit is contained in:
@@ -6,42 +6,38 @@
|
||||
#include <iostream> // for basic_ostream, char_traits, operator<<
|
||||
#include "utils.h" // for HiScoreEntry
|
||||
|
||||
// Constructor
|
||||
ManageHiScoreTable::ManageHiScoreTable(std::vector<HiScoreEntry> *table)
|
||||
: table_(table) {}
|
||||
|
||||
// Resetea la tabla a los valores por defecto
|
||||
void ManageHiScoreTable::clear()
|
||||
{
|
||||
// Limpia la tabla
|
||||
table_->clear();
|
||||
table_.clear();
|
||||
|
||||
// Añade 10 entradas predefinidas
|
||||
table_->push_back({"Bry", 1000000});
|
||||
table_->push_back({"Usufondo", 500000});
|
||||
table_->push_back({"G.Lucas", 100000});
|
||||
table_->push_back({"P.Delgat", 50000});
|
||||
table_->push_back({"P.Arrabalera", 10000});
|
||||
table_->push_back({"Pelechano", 5000});
|
||||
table_->push_back({"Sahuquillo", 1000});
|
||||
table_->push_back({"Bacteriol", 500});
|
||||
table_->push_back({"Pepe", 200});
|
||||
table_->push_back({"Rosita", 100});
|
||||
table_.push_back({"Bry", 1000000});
|
||||
table_.push_back({"Usufondo", 500000});
|
||||
table_.push_back({"G.Lucas", 100000});
|
||||
table_.push_back({"P.Delgat", 50000});
|
||||
table_.push_back({"P.Arrabalera", 10000});
|
||||
table_.push_back({"Pelechano", 5000});
|
||||
table_.push_back({"Sahuquillo", 1000});
|
||||
table_.push_back({"Bacteriol", 500});
|
||||
table_.push_back({"Pepe", 200});
|
||||
table_.push_back({"Rosita", 100});
|
||||
}
|
||||
|
||||
// Añade un elemento a la tabla
|
||||
void ManageHiScoreTable::add(HiScoreEntry entry)
|
||||
{
|
||||
// Añade la entrada a la tabla
|
||||
table_->push_back(entry);
|
||||
table_.push_back(entry);
|
||||
|
||||
// Ordena la tabla
|
||||
sort();
|
||||
|
||||
// Deja solo las 10 primeras entradas
|
||||
if (static_cast<int>(table_->size()) > 10)
|
||||
if (static_cast<int>(table_.size()) > 10)
|
||||
{
|
||||
table_->resize(10);
|
||||
table_.resize(10);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +49,7 @@ void ManageHiScoreTable::sort()
|
||||
bool operator()(const HiScoreEntry &a, const HiScoreEntry &b) const { return a.score > b.score; }
|
||||
} custom_less;
|
||||
|
||||
std::sort(table_->begin(), table_->end(), custom_less);
|
||||
std::sort(table_.begin(), table_.end(), custom_less);
|
||||
}
|
||||
|
||||
// Carga la tabla con los datos de un fichero
|
||||
@@ -68,7 +64,7 @@ bool ManageHiScoreTable::loadFromFile(const std::string &file_path)
|
||||
const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1);
|
||||
std::cout << "Reading file: " << file_name << std::endl;
|
||||
|
||||
for (auto &entry : *table_)
|
||||
for (auto &entry : table_)
|
||||
{
|
||||
int nameSize = 0;
|
||||
|
||||
@@ -116,12 +112,12 @@ bool ManageHiScoreTable::saveToFile(const std::string &file_path)
|
||||
if (file)
|
||||
{
|
||||
// Guarda los datos
|
||||
for (int i = 0; i < (int)table_->size(); ++i)
|
||||
for (int i = 0; i < (int)table_.size(); ++i)
|
||||
{
|
||||
SDL_RWwrite(file, &table_->at(i).score, sizeof(int), 1);
|
||||
const int nameSize = (int)table_->at(i).name.size();
|
||||
SDL_RWwrite(file, &table_.at(i).score, sizeof(int), 1);
|
||||
const int nameSize = (int)table_.at(i).name.size();
|
||||
SDL_RWwrite(file, &nameSize, sizeof(int), 1);
|
||||
SDL_RWwrite(file, table_->at(i).name.c_str(), nameSize, 1);
|
||||
SDL_RWwrite(file, table_.at(i).name.c_str(), nameSize, 1);
|
||||
}
|
||||
|
||||
std::cout << "Writing file: " << file_name.c_str() << std::endl;
|
||||
|
||||
Reference in New Issue
Block a user