Posibilidad de activar o desactivar el modo online
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user