#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"

#define w 1280
#define h 800
#define mag 800
#define zfactor 1


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

    mode * g = new title();
    int m = 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->up();
		if (app->GetInput().IsKeyDown(Key::S) || app->GetInput().IsKeyDown(Key::Down))
            g->down();
		if (app->GetInput().IsKeyDown(Key::A) || app->GetInput().IsKeyDown(Key::Left))
			g->left();
		if (app->GetInput().IsKeyDown(Key::D) || app->GetInput().IsKeyDown(Key::Right))
			g->right();
		if (app->GetInput().IsKeyDown(Key::Space))
			g->space();
		if (app->GetInput().IsKeyDown(Key::LShift))
			g->shift();
        if (app->GetInput().IsKeyDown(Key::Return) && m==0)
        {
            m=1;
            delete g;
            g = new game();
        }


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

        while(g->thereIsLineToDraw())
        {
            camera::draw cam = g->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
