diff --git a/source/common/screen.cpp b/source/common/screen.cpp index 3f97aaf..b96803f 100644 --- a/source/common/screen.cpp +++ b/source/common/screen.cpp @@ -12,7 +12,8 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options this->asset = asset; // Crea los objetos - notify = new Notify(renderer, asset->get("smb2_big.png"), asset->get("smb2_big.txt")); + //notify = new Notify(renderer, asset->get("smb2_big.png"), asset->get("smb2_big.txt")); + notify = new Notify(renderer, asset->get("smb2.png"), asset->get("smb2.txt")); gameCanvasWidth = gameInternalResX; gameCanvasHeight = gameInternalResY; diff --git a/source/common/utils.h b/source/common/utils.h index eccc447..8b3d7c9 100644 --- a/source/common/utils.h +++ b/source/common/utils.h @@ -86,6 +86,7 @@ struct input_t // Estructura para el servicio online struct online_t { + bool enabled; // Indica si se quiere usar el modo online o no std::string gameID; // Identificador del juego para los servicios online std::string jailerID; // Identificador del jugador para los servicios online int score; // Puntuación almacenada online diff --git a/source/director.cpp b/source/director.cpp index ba2cd0a..9958f68 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -21,8 +21,10 @@ Director::Director(std::string path) section.name = PROG_SECTION_QUIT; } - // Crea el puntero a la estructura y carga el fichero de configuración - options = new options_t; + // Inicializa las opciones del programa + initOptions(); + + // Carga el fichero de configuración loadConfigFile(); // Inicializa SDL @@ -292,9 +294,11 @@ bool Director::setFileList() return asset->check(); } -// Carga el fichero de configuración -bool Director::loadConfigFile() +// Inicializa las opciones del programa +void Director::initOptions() { + options = new options_t; + // Pone unos valores por defecto options->input.clear(); @@ -322,10 +326,17 @@ bool Director::loadConfigFile() options->keepAspect = true; options->borderSize = 0.0f; options->borderEnabled = false; + + // Online + options->online.enabled = true; options->online.gameID = "coffee_crisis"; options->online.jailerID = ""; options->online.score = 0; +} +// Carga el fichero de configuración +bool Director::loadConfigFile() +{ // Indicador de éxito en la carga bool success = true; @@ -512,6 +523,13 @@ void Director::run() // Inicializa los servicios online void Director::initOnline() { + if (!options->online.enabled) + { + screen->showText("Modo Online deshabilitado"); + std::cout << "Modo Online deshabilitado" << std::endl; + return; + } + // Obtiene la información online if (jscore::initOnlineScore(options->online.gameID)) { @@ -535,28 +553,32 @@ void Director::initOnline() f.close(); } } + else + { // Escribe en el fichero + f << ""; + } f.close(); if (options->online.jailerID == "") - { + { // Jailer ID no definido screen->showText("No ha especificado ningun Jailer ID"); std::cout << "No ha especificado ningun Jailer ID" << std::endl; } else - { + { // Jailer ID iniciado screen->showText(options->online.jailerID + " ha iniciado sesion"); std::cout << options->online.jailerID << " ha iniciado sesion" << std::endl; - } - // Obten la puntuación online - const int points = jscore::getUserPoints(options->online.gameID, options->online.jailerID); - if (points == 0) - { - screen->showText("No se ha podido obtener la puntuacion online"); - std::cout << "No se ha podido obtener la puntuacion online" << std::endl; - } - else - { - options->online.score = points; + // Obten la puntuación online + const int points = jscore::getUserPoints(options->online.gameID, options->online.jailerID); + if (points == 0) + { // Fallo de conexión o no hay registros + screen->showText("No se ha podido obtener la puntuacion online"); + std::cout << "No se ha podido obtener la puntuacion online" << std::endl; + } + else + { + options->online.score = points; + } } } \ No newline at end of file diff --git a/source/director.h b/source/director.h index ea89c08..5ee2548 100644 --- a/source/director.h +++ b/source/director.h @@ -60,6 +60,9 @@ private: // Inicializa los servicios online void initOnline(); + // Inicializa las opciones del programa + void initOptions(); + // Crea el indice de ficheros bool setFileList(); diff --git a/source/game.cpp b/source/game.cpp index 165fdeb..6420bd9 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -730,6 +730,11 @@ bool Game::saveScoreFile() // Sube la puntuación online bool Game::sendOnlineScore() { + if (!options->online.enabled) + { + return true; + } + const int score = players.at(0)->getScore(); if (score <= options->online.score) { @@ -1683,9 +1688,15 @@ void Game::renderScoreBoard() // HI-SCORE textScoreBoard->writeCentered(PLAY_AREA_CENTER_X, offset3, lang->getText(56)); - // textScoreBoard->writeCentered(PLAY_AREA_CENTER_X, offset4, updateScoreText(hiScore)); - const std::string txt = jscore::getUserName(0) + " - " + updateScoreText((Uint32)jscore::getPoints(0)); - textScoreBoard->writeCentered(PLAY_AREA_CENTER_X, offset4, txt); + if (options->online.enabled) + { + const std::string txt = jscore::getUserName(0) + " - " + updateScoreText((Uint32)jscore::getPoints(0)); + textScoreBoard->writeCentered(PLAY_AREA_CENTER_X, offset4, txt); + } + else + { + textScoreBoard->writeCentered(PLAY_AREA_CENTER_X, offset4, updateScoreText(hiScore)); + } } // Actualiza las variables del jugador