Sanejar codi

This commit is contained in:
2025-02-21 15:13:57 +01:00
parent cf19194e7a
commit 1e73a3159f
5 changed files with 35 additions and 44 deletions

View File

@@ -18,6 +18,7 @@
#include <iostream> // for cout
#include <string> // for basic_string, operator+, char_t...
#include <vector> // for vector
#include <memory>
#include "asset.h" // for Asset, assetType
#include "const.h" // for SECTION_PROG_LOGO, GAMECANVAS_H...
#include "game.h" // for Game
@@ -35,8 +36,9 @@
#endif
// Constructor
Director::Director(int argc, char *argv[])
Director::Director(int argc, const char *argv[])
{
std::cout << "Game start" << std::endl;
// Inicializa variables
section = new section_t();
section->name = SECTION_PROG_LOGO;
@@ -99,6 +101,8 @@ Director::~Director()
SDL_DestroyWindow(window);
SDL_Quit();
std::cout << "\nBye!" << std::endl;
}
// Inicializa el objeto input
@@ -416,7 +420,7 @@ void Director::initOptions()
}
// Comprueba los parametros del programa
void Director::checkProgramArguments(int argc, char *argv[])
void Director::checkProgramArguments(int argc, const char *argv[])
{
// Establece la ruta del programa
executablePath = argv[0];
@@ -639,34 +643,30 @@ bool Director::saveConfigFile()
void Director::runLogo()
{
logo = new Logo(renderer, screen, asset, input, section);
auto logo = std::make_unique<Logo>(renderer, screen, asset, input, section);
logo->run();
delete logo;
}
void Director::runIntro()
{
intro = new Intro(renderer, screen, asset, input, lang, section);
auto intro = std::make_unique<Intro>(renderer, screen, asset, input, lang, section);
intro->run();
delete intro;
}
void Director::runTitle()
{
title = new Title(renderer, screen, input, asset, options, lang, section);
auto title = std::make_unique<Title>(renderer, screen, input, asset, options, lang, section);
title->run();
delete title;
}
void Director::runGame()
{
const int numPlayers = section->subsection == SUBSECTION_GAME_PLAY_1P ? 1 : 2;
game = new Game(numPlayers, 0, renderer, screen, asset, lang, input, false, options, section);
auto game = std::make_unique<Game>(numPlayers, 0, renderer, screen, asset, lang, input, false, options, section);
game->run();
delete game;
}
void Director::run()
int Director::run()
{
// Bucle principal
while (section->name != SECTION_PROG_QUIT)
@@ -690,6 +690,8 @@ void Director::run()
break;
}
}
return 0;
}
// Asigna variables a partir de dos cadenas

View File

@@ -24,10 +24,6 @@ private:
SDL_Window *window; // La ventana donde dibujamos
SDL_Renderer *renderer; // El renderizador de la ventana
Screen *screen; // Objeto encargado de dibujar en pantalla
Logo *logo; // Objeto para la sección del logo
Intro *intro; // Objeto para la sección de la intro
Title *title; // Objeto para la sección del titulo y el menu de opciones
Game *game; // Objeto para la sección del juego
Input *input; // Objeto Input para gestionar las entradas
Lang *lang; // Objeto para gestionar los textos en diferentes idiomas
Asset *asset; // Objeto que gestiona todos los ficheros de recursos
@@ -63,7 +59,7 @@ private:
bool saveConfigFile();
// Comprueba los parametros del programa
void checkProgramArguments(int argc, char *argv[]);
void checkProgramArguments(int argc, const char *argv[]);
// Crea la carpeta del sistema donde guardar datos
void createSystemFolder(const std::string &folder);
@@ -82,11 +78,11 @@ private:
public:
// Constructor
Director(int argc, char *argv[]);
Director(int argc, const char *argv[]);
// Destructor
~Director();
// Bucle principal
void run();
int run();
};

View File

@@ -39,24 +39,14 @@ Reescribiendo el código el 27/09/2022
*/
#include <iostream> // for char_traits, basic_ostream, operator<<, endl
#include "director.h" // for Director
#include <memory>
#include "director.h"
int main(int argc, char *argv[])
{
std::cout << "Starting the game..." << std::endl
<< std::endl;
// Crea el objeto Director
Director *director = new Director(argc, argv);
auto director = std::make_unique<Director>(argc, const_cast<const char **>(argv));
// Bucle principal
director->run();
// Destruye el objeto Director
delete director;
std::cout << "\nShutting down the game..." << std::endl;
return 0;
}
return director->run();
}