#include "Level.h"
#include "Case.h"

#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>

#include <iostream>
#include <ctime>
#include <vector>

using namespace sf;

Level::Level(Case* aCase, int width, int height)
{
    m_width=width;
    m_height=height;
    m_case=aCase;
    srand(time(NULL));

}


std::pair<int,int> Level::findAnother2(char val)
{

  int x(0),y(0);
  while (m_tab[y][x]!=val)
  {
      x=rand()%(m_width+1), y=rand()%(m_height+1);
  }
  return std::pair<int,int> (x,y);


}

void Level::create()
{
    std::string line;
    for(int i(0);i<m_width;i++)
    {
        m_tab.push_back(line);
        for (int j(0);j<m_height-1;j++)
        {

            int temp(rand()%26);
        if (temp==0){m_tab[i]+='3';}
        if (temp==1){m_tab[i]+='4';}
        if (temp==2){m_tab[i]+='5';}
        else {m_tab[i]+='0';}
        //std::cout<<m_tab[i][j];
        }
        }
    for (int i(0);i<m_width;i++)
    {
        m_tab[i][0]='5';
        m_tab[i][m_height-2]='5';
    }
    for (int i(0);i<m_height;i++)
    {
        m_tab[0][i]='5';
        m_tab[m_width-1][i]='5';

    }

}

const void Level::draw()
{
    for(int i(0);i<m_width;i++)
    {
        for (int j(0);j<m_height;j++)
        {
            m_case->draw(m_tab[i][j]-'0',0,i,j);
        }
    }
}

Level::~Level()
{
    //dtor
}
