#include <string>
#include "AppController.h"
#include "SequenceController.h"
#include "MenuController.h"
#include "PasswordController.h"
#include "PrefaseController.h"
#include "GameController.h"
#include "PostfaseController.h"
#include "MortController.h"
#include "const.h"

AppController::AppController(int pMode)
{
	gameInfo = new GameInfo(pMode);
}

AppController::~AppController(void)
{
}

bool AppController::Init(void)
{
    if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 ) { return false; }

	drawManager = new DrawManager(gameInfo->modeGrafic);
	inputManager = new InputManager(gameInfo);

	if ( !drawManager->Init() ) { return false; }
	music_init();

	return true;
}

void AppController::Go()
{
	if (!Init()) gameInfo->estado = ESTADO_SALIR;

	while ( gameInfo->estado != ESTADO_SALIR ) {
		switch ( gameInfo->estado ) {
			case ESTADO_SEQUENCIA:
				SequenceController *sequenceController;
				sequenceController = new SequenceController(drawManager, inputManager);
				sequenceController->Go(gameInfo);
				delete sequenceController;
				break;
			case ESTADO_MENU:
				MenuController *menuController;
				menuController = new MenuController(drawManager, inputManager);
				menuController->Go(gameInfo);
				delete menuController;
				break;
			case ESTADO_PASSWORD:
				PasswordController *passwordController;
				passwordController = new PasswordController(drawManager, inputManager);
				passwordController->Go(gameInfo);
				delete passwordController;
				break;
			case ESTADO_PREFASE:
				PrefaseController *prefaseController;
				prefaseController = new PrefaseController(drawManager, inputManager);
				prefaseController->Go(gameInfo);
				delete prefaseController;
				break;
			case ESTADO_JUEGO:
				GameController *gameController;
				gameController = new GameController(drawManager, inputManager);
				gameController->Go(gameInfo);
				delete gameController;
				break;
			case ESTADO_POSTFASE:
				PostfaseController *postfaseController;
				postfaseController = new PostfaseController(drawManager, inputManager);
				postfaseController->Go(gameInfo);
				delete postfaseController;
				break;
			case ESTADO_MORT:
				MortController *mortController;
				mortController = new MortController(drawManager, inputManager);
				mortController->Go(gameInfo);
				delete mortController;
				break;
		}
	}

	Finalize();
}

void AppController::Finalize(void)
{
	delete drawManager;
	delete inputManager;
	delete gameInfo;

	SDL_Quit();
}