#include "Ramsey.h"
#include <vector>

class Game : public sf::Drawable {
private:
    int n; //matrix size;
    int k; //number of characters
    Ramsey* R; //Acces to a Ramsey object
    //Here's a way to handle the buttons that's pretty slick!
    std::vector<std::pair<sf::RectangleShape, void (Game::*)(sf::Event)>> buttons;
    void start(sf::Event e); // The function that gets called when the button is pushed
    void stop(sf::Event e);
    void inc_n(sf::Event e);
    void dec_n(sf::Event e);
    void inc_k(sf::Event e);
    void dec_k(sf::Event e);
public:
    Game(int N = 8, int K = 8) : n(N), k(K) {  //Game constructor
    	//Define the buttons' rectangles.
        sf::RectangleShape start_button_rect        (sf::Vector2f(150,60));
        sf::RectangleShape stop_button_rect         (sf::Vector2f(150,60));
        sf::RectangleShape increase_n_button_rect   (sf::Vector2f(150,30));
        sf::RectangleShape decrease_n_button_rect   (sf::Vector2f(150,30));
        sf::RectangleShape increase_k_button_rect   (sf::Vector2f(150,30));
        sf::RectangleShape decrease_k_button_rect   (sf::Vector2f(150,30));

        start_button_rect.setFillColor              (sf::Color(200,200,200));
        stop_button_rect.setFillColor               (sf::Color(150,150,150));
        increase_n_button_rect.setFillColor         (sf::Color(100,100,100));
        decrease_n_button_rect.setFillColor         (sf::Color(175,175,175));
        increase_k_button_rect.setFillColor         (sf::Color(50,50,50));
        decrease_k_button_rect.setFillColor         (sf::Color(75,75,75));

        start_button_rect.setPosition       (0,600);
        stop_button_rect.setPosition        (150,600);
        increase_n_button_rect.setPosition  (300,600);
        decrease_n_button_rect.setPosition  (300,630);
        increase_k_button_rect.setPosition  (450,600);
        decrease_k_button_rect.setPosition  (450,630);

        buttons.push_back(std::pair<sf::RectangleShape, void (Game::*)(sf::Event)>
        	(start_button_rect, Game::start));
        buttons.push_back(std::pair<sf::RectangleShape, void (Game::*)(sf::Event)>
        	(stop_button_rect, Game::stop));
        buttons.push_back(std::pair<sf::RectangleShape, void (Game::*)(sf::Event)>
        	(increase_n_button_rect, Game::inc_n));
        buttons.push_back(std::pair<sf::RectangleShape, void (Game::*)(sf::Event)>
        	(decrease_n_button_rect, Game::dec_n));
        buttons.push_back(std::pair<sf::RectangleShape, void (Game::*)(sf::Event)>
        	(increase_k_button_rect, Game::inc_k));
        buttons.push_back(std::pair<sf::RectangleShape, void (Game::*)(sf::Event)>
        	(decrease_k_button_rect, Game::dec_k));

        R = new Ramsey(n,k); //Allocate memory for the Ramsey object on the heap.
    }

    void process(sf::Event event)   {
        if ( event.type == sf::Event::MouseButtonPressed) {
            for (auto b : buttons) {
                if(b.first.getGlobalBounds().contains(event.mouseButton.x,event.mouseButton.y)) {
                    (this->*b.second)(event);
                }
            }
        }
    }
    void update(int n = 8, int k = 8)  {
        R->update();  // Create a new random matrix
    }
    void draw(sf::RenderTarget& target, sf::RenderStates states) const; //Game has its own draw.
};

void Game::start(sf::Event e) {
   // Set R's is_valid to false, you need to make a new one.
}

void Game::stop(sf::Event e) {
    // Set R's is_valid to true, you have achieved Ramseyness.
}

void Game::inc_n(sf::Event e) {
    // Call R's adjust_n function with offset = 1.
}

void Game::dec_n(sf::Event e) {
    // Call R's adjust_n function with offset = -1.
}

void Game::inc_k(sf::Event e) {
    // Call R's adjust_k function with offset = 1.
}

void Game::dec_k(sf::Event e) {
    // Call R's adjust_n function with offset = -1.
}

void Game::draw(sf::RenderTarget& target, sf::RenderStates states) const {
    for(auto b : buttons) target.draw(b.first);
	// Call R's draw function with parameters target and states.
}