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;
|
this->asset = asset;
|
||||||
|
|
||||||
// Crea los objetos
|
// 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;
|
gameCanvasWidth = gameInternalResX;
|
||||||
gameCanvasHeight = gameInternalResY;
|
gameCanvasHeight = gameInternalResY;
|
||||||
|
|||||||
@@ -86,6 +86,7 @@ struct input_t
|
|||||||
// Estructura para el servicio online
|
// Estructura para el servicio online
|
||||||
struct online_t
|
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 gameID; // Identificador del juego para los servicios online
|
||||||
std::string jailerID; // Identificador del jugador para los servicios online
|
std::string jailerID; // Identificador del jugador para los servicios online
|
||||||
int score; // Puntuación almacenada online
|
int score; // Puntuación almacenada online
|
||||||
|
|||||||
@@ -21,8 +21,10 @@ Director::Director(std::string path)
|
|||||||
section.name = PROG_SECTION_QUIT;
|
section.name = PROG_SECTION_QUIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Crea el puntero a la estructura y carga el fichero de configuración
|
// Inicializa las opciones del programa
|
||||||
options = new options_t;
|
initOptions();
|
||||||
|
|
||||||
|
// Carga el fichero de configuración
|
||||||
loadConfigFile();
|
loadConfigFile();
|
||||||
|
|
||||||
// Inicializa SDL
|
// Inicializa SDL
|
||||||
@@ -292,9 +294,11 @@ bool Director::setFileList()
|
|||||||
return asset->check();
|
return asset->check();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Carga el fichero de configuración
|
// Inicializa las opciones del programa
|
||||||
bool Director::loadConfigFile()
|
void Director::initOptions()
|
||||||
{
|
{
|
||||||
|
options = new options_t;
|
||||||
|
|
||||||
// Pone unos valores por defecto
|
// Pone unos valores por defecto
|
||||||
options->input.clear();
|
options->input.clear();
|
||||||
|
|
||||||
@@ -322,10 +326,17 @@ bool Director::loadConfigFile()
|
|||||||
options->keepAspect = true;
|
options->keepAspect = true;
|
||||||
options->borderSize = 0.0f;
|
options->borderSize = 0.0f;
|
||||||
options->borderEnabled = false;
|
options->borderEnabled = false;
|
||||||
|
|
||||||
|
// Online
|
||||||
|
options->online.enabled = true;
|
||||||
options->online.gameID = "coffee_crisis";
|
options->online.gameID = "coffee_crisis";
|
||||||
options->online.jailerID = "";
|
options->online.jailerID = "";
|
||||||
options->online.score = 0;
|
options->online.score = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Carga el fichero de configuración
|
||||||
|
bool Director::loadConfigFile()
|
||||||
|
{
|
||||||
// Indicador de éxito en la carga
|
// Indicador de éxito en la carga
|
||||||
bool success = true;
|
bool success = true;
|
||||||
|
|
||||||
@@ -512,6 +523,13 @@ void Director::run()
|
|||||||
// Inicializa los servicios online
|
// Inicializa los servicios online
|
||||||
void Director::initOnline()
|
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
|
// Obtiene la información online
|
||||||
if (jscore::initOnlineScore(options->online.gameID))
|
if (jscore::initOnlineScore(options->online.gameID))
|
||||||
{
|
{
|
||||||
@@ -535,23 +553,26 @@ void Director::initOnline()
|
|||||||
f.close();
|
f.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{ // Escribe en el fichero
|
||||||
|
f << "";
|
||||||
|
}
|
||||||
f.close();
|
f.close();
|
||||||
|
|
||||||
if (options->online.jailerID == "")
|
if (options->online.jailerID == "")
|
||||||
{
|
{ // Jailer ID no definido
|
||||||
screen->showText("No ha especificado ningun Jailer ID");
|
screen->showText("No ha especificado ningun Jailer ID");
|
||||||
std::cout << "No ha especificado ningun Jailer ID" << std::endl;
|
std::cout << "No ha especificado ningun Jailer ID" << std::endl;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{ // Jailer ID iniciado
|
||||||
screen->showText(options->online.jailerID + " ha iniciado sesion");
|
screen->showText(options->online.jailerID + " ha iniciado sesion");
|
||||||
std::cout << options->online.jailerID << " ha iniciado sesion" << std::endl;
|
std::cout << options->online.jailerID << " ha iniciado sesion" << std::endl;
|
||||||
}
|
|
||||||
|
|
||||||
// Obten la puntuación online
|
// Obten la puntuación online
|
||||||
const int points = jscore::getUserPoints(options->online.gameID, options->online.jailerID);
|
const int points = jscore::getUserPoints(options->online.gameID, options->online.jailerID);
|
||||||
if (points == 0)
|
if (points == 0)
|
||||||
{
|
{ // Fallo de conexión o no hay registros
|
||||||
screen->showText("No se ha podido obtener la puntuacion online");
|
screen->showText("No se ha podido obtener la puntuacion online");
|
||||||
std::cout << "No se ha podido obtener la puntuacion online" << std::endl;
|
std::cout << "No se ha podido obtener la puntuacion online" << std::endl;
|
||||||
}
|
}
|
||||||
@@ -560,3 +581,4 @@ void Director::initOnline()
|
|||||||
options->online.score = points;
|
options->online.score = points;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -60,6 +60,9 @@ private:
|
|||||||
// Inicializa los servicios online
|
// Inicializa los servicios online
|
||||||
void initOnline();
|
void initOnline();
|
||||||
|
|
||||||
|
// Inicializa las opciones del programa
|
||||||
|
void initOptions();
|
||||||
|
|
||||||
// Crea el indice de ficheros
|
// Crea el indice de ficheros
|
||||||
bool setFileList();
|
bool setFileList();
|
||||||
|
|
||||||
|
|||||||
@@ -730,6 +730,11 @@ bool Game::saveScoreFile()
|
|||||||
// Sube la puntuación online
|
// Sube la puntuación online
|
||||||
bool Game::sendOnlineScore()
|
bool Game::sendOnlineScore()
|
||||||
{
|
{
|
||||||
|
if (!options->online.enabled)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
const int score = players.at(0)->getScore();
|
const int score = players.at(0)->getScore();
|
||||||
if (score <= options->online.score)
|
if (score <= options->online.score)
|
||||||
{
|
{
|
||||||
@@ -1683,10 +1688,16 @@ void Game::renderScoreBoard()
|
|||||||
|
|
||||||
// HI-SCORE
|
// HI-SCORE
|
||||||
textScoreBoard->writeCentered(PLAY_AREA_CENTER_X, offset3, lang->getText(56));
|
textScoreBoard->writeCentered(PLAY_AREA_CENTER_X, offset3, lang->getText(56));
|
||||||
// textScoreBoard->writeCentered(PLAY_AREA_CENTER_X, offset4, updateScoreText(hiScore));
|
if (options->online.enabled)
|
||||||
|
{
|
||||||
const std::string txt = jscore::getUserName(0) + " - " + updateScoreText((Uint32)jscore::getPoints(0));
|
const std::string txt = jscore::getUserName(0) + " - " + updateScoreText((Uint32)jscore::getPoints(0));
|
||||||
textScoreBoard->writeCentered(PLAY_AREA_CENTER_X, offset4, txt);
|
textScoreBoard->writeCentered(PLAY_AREA_CENTER_X, offset4, txt);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
textScoreBoard->writeCentered(PLAY_AREA_CENTER_X, offset4, updateScoreText(hiScore));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Actualiza las variables del jugador
|
// Actualiza las variables del jugador
|
||||||
void Game::updatePlayers()
|
void Game::updatePlayers()
|
||||||
|
|||||||
Reference in New Issue
Block a user