#include "SDL/SDL.h"
#include "SDL/SDL_ttf.h"
#include "SDL/SDL_image.h"
#include "SDL/SDL_mixer.h"
#include <cstdlib>
#include "functions.h"
#include "clase.h"
#include "initializare.h"
#include "instructiuni.h"
#include "start.h"
#include "fstream"
//patratul verde= -4 patrate albastre
//
using namespace std;


int main (int argc, char* args[])
{
	SDL_Init(SDL_INIT_EVERYTHING);
	TTF_Init();
	Mix_OpenAudio (22050, MIX_DEFAULT_FORMAT, 2, 4096);//SUNET
	font=TTF_OpenFont("calibrib.ttf",40);
	//SDL_ShowCursor(SDL_DISABLE);
	screen = SDL_SetVideoMode( 1000, 750, 32, SDL_FULLSCREEN);
	init();
	//citesc highscore din fisier
	ifstream fin("resources/highscore.mal");
	fin >>high;
	fin.close();
	//
	Mix_PlayMusic(muzica, -1);
	//
	while (2)
    {
        start.coordonate(1.25*250, 1.25*200);
        start.miscare();
        instructiuni.miscare();
        highscores.miscare();
        iesire.miscare();
        wallpaper.deseneaza();
        start.deseneaza();
        instructiuni.deseneaza();
        highscores.deseneaza();
        iesire.deseneaza();
        /*if (sound.click() && sound.hover==0)
        {
            sound.hover=1;
            Mix_HaltMusic();
        }

        if (sound.click() && sound.hover==1)
        {
            sound.hover=0;
            Mix_PlayMusic(muzica, -1);
        }*/
        //sound.deseneaza();

        while (SDL_PollEvent(&x_out))
            if (x_out.type==SDL_QUIT)
            {
                close_sdl();
                exit(EXIT_SUCCESS);
            }

        Uint8 *keystates = SDL_GetKeyState(NULL);//toate tastele si statusurile lor

        if (iesire.click()) {close_sdl(); exit(EXIT_SUCCESS);}
        if (keystates[SDLK_LALT] && keystates[SDLK_F4]) {close_sdl(); exit(EXIT_SUCCESS);}

        if (instructiuni.click()) instr();
        if (highscores.click())
        {
            while (2)
            {
                wallpaper.deseneaza();
                inapoi.deseneaza();
                inapoi.miscare();

                if (inapoi.click()) break;

                while (SDL_PollEvent(&x_out))
                    if (x_out.type==SDL_QUIT)
                    {
                        close_sdl();
                        exit(EXIT_SUCCESS);
                    }

                Uint8 *keystates = SDL_GetKeyState( NULL );//toate tastele si statusurile lor
                if (keystates[SDLK_LALT] && keystates[SDLK_F4]) {close_sdl(); exit(EXIT_SUCCESS);}

                message = TTF_RenderText_Solid( font, high, textColor );
                blit_surface(message, screen, 350, 260, NULL);

                SDL_Flip(screen);
            }
        }
        //start
        if (start.click()) incepe();

        SDL_Flip(screen);
    }
    close_sdl();
	return 0;
}

