#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>

using namespace sf;

#include <assert.h>
#include <vector>

#include <string>
#include <iostream>
#include <fstream>
using namespace std;

#include "../shell.hpp"
#include "../disk.hpp"
#include "../shellSTD.hpp"
#include "../point.hpp"
#include "../fly.hpp"
#include "../camera.hpp"
#include "../list.hpp"
#include "../bullet.hpp"

#include "../game.hpp"
#include "../title.hpp"
#include "../menu.hpp"

#define w 1280
#define h 800
#define mag 800
#define zfactor 1


//==========================================
int main()
{

    mode * g[3] = {new title(), new menu(), new game()};
    int m = 0;
    int mute = 0;

    RenderWindow* app = new RenderWindow(VideoMode(w, h, 32), "B==D");
    app->SetFramerateLimit(60);
    while (app->IsOpened())
    {
        //clear screen
        app->Clear(Color(0, 0, 0));
        //recevoir la event queue
        Event* event = new Event();
        //pour chaque évenement de la queue
        while (app->GetEvent(*event))
            if (event->Type == Event::Closed)
                app->Close();
        if (app->GetInput().IsKeyDown(Key::Escape))
            return EXIT_SUCCESS;
//        if (app->GetInput().IsKeyDown(Key::Num1))
//            thirdPerson = true;
//        if (app->GetInput().IsKeyDown(Key::Num2))
//            thirdPerson = false;

		//move tank
		if (app->GetInput().IsKeyDown(Key::W) || app->GetInput().IsKeyDown(Key::Up))
            g[m]->up();
		if (app->GetInput().IsKeyDown(Key::S) || app->GetInput().IsKeyDown(Key::Down))
            g[m]->down();
		if (app->GetInput().IsKeyDown(Key::A) || app->GetInput().IsKeyDown(Key::Left))
			g[m]->left();
		if (app->GetInput().IsKeyDown(Key::D) || app->GetInput().IsKeyDown(Key::Right))
			g[m]->right();
		if (app->GetInput().IsKeyDown(Key::Space))
			g[m]->space();
		if (app->GetInput().IsKeyDown(Key::LShift))
			g[m]->shift();
        if (app->GetInput().IsKeyDown(Key::Return) && mute==0)
        {
                m = g[m]->getMode();
                mute = 10;
        }
        if (mute)
            mute--;




        g[m]->update();
        app->Clear(Color(g[m]->getBg().r, g[m]->getBg().g, g[m]->getBg().b));

        while(g[m]->thereIsLineToDraw())
        {
            camera::draw cam = g[m]->nextLineToDraw();
            Color col = Color(cam._r,
                        cam._g,
                        cam._b);
            Shape Line = Shape::Line(cam._p1X+w/2,
                               cam._p1Y+h/2,
                               cam._p2X+w/2,
                               cam._p2Y+h/2,
                               1, col,
                               0, Color(255,255,255));
            app->Draw(Line);
        }
        //refresh screen
        app->Display();
    }

    list<int> test;
    cout << "list test\n";

    for(int i=0;i<10;i++)
        test.push_front(i);

    for(list<int>::iterator it = test.begin(); it != it->end(); it = it->next() )
        cout << it->data() << " ";
    cout << endl;

    while(!test.empty())
    {
        test.pop_back();
        for(list<int>::iterator it = test.begin(); it != it->end(); it = it->next() )
            cout << it->data() << " ";
        cout << endl;
    }


    return EXIT_SUCCESS;
}

//ebauche de lecteur de fichier
