

#include "classes.h"

using namespace std;

/////affichage

void affichage(monde world[10][10])
{
	for ( int i = 0; i < 10;i++)
		{
			cout << endl;
			for( int j= 0; j < 10; j++)
			{
				
				cout << "|[" <<world[i][j].selsMineraux <<"]";
				if(world[i][j].ev1.type != "herbe")// d'abord le sol = herbe
				{
					cout << "s" ;
					if(world[i][j].ev2.type == "mouton" && world[i][j].ev3.type == "mouton")//cas ou l'on a sable + 2 moutons
					{
						
						cout << "mm" ;
					}
					else if((world[i][j].ev2.type == "loup" && world[i][j].ev3.type == "mouton") || ( world[i][j].ev2.type == "mouton" && world[i][j].ev3.type == "loup"))
					{//cas ou l'on a sable + mouton+ loup
						
						cout << "lm" ;
					}
					else if(world[i][j].ev2.type == "loup" && world[i][j].ev3.type == "loup" )
					{//cas ou l'on a sable + 2 loups
						
						cout << "ll" ;
					}
					else if(world[i][j].ev2.type == "mouton"  || world[i][j].ev3.type == "mouton")
					{//cas ou l'on a sable + mouton
						
						cout << "m " ;
					}
					else if(world[i][j].ev2.type == "loup"  || world[i][j].ev3.type == "loup")
					{//cas ou l'on a sable + loup
						
						cout << "l " ;
					}
					else
					{//cas ou l'on a que du sable
						cout<< "  ";
					}
				}
				else if(world[i][j].ev1.type == "herbe")// ici on test pour l'herbe
				{
					cout << "h" ;
					if(world[i][j].ev2.type == "mouton" && world[i][j].ev3.type == "mouton")//cas ou l'on a herbe + 2 moutons
					{
						
						cout << "mm" ;
					}
					else if((world[i][j].ev2.type == "loup" && world[i][j].ev3.type == "mouton") || ( world[i][j].ev2.type == "mouton" && world[i][j].ev3.type == "loup"))
					{//cas ou l'on a herbe + mouton+ loup
						
						cout << "lm" ;
					}
					else if(world[i][j].ev2.type == "loup" && world[i][j].ev3.type == "loup" )
					{//cas ou l'on a herbe + 2 loups
						
						cout << "ll" ;
					}
					else if(world[i][j].ev2.type == "mouton"  || world[i][j].ev3.type == "mouton")
					{//cas ou l'on a herbe + mouton
						
						cout << "m " ;
					}
					else if(world[i][j].ev2.type == "loup"  || world[i][j].ev3.type == "loup" )
					{//cas ou l'on a herbe + loup
						
						cout << "l " ;
					}
					else
					{//cas ou l'on a herbe tout seul
						
						cout << "  " ;
					}
				}
				
			}
	}
}
//initialisation du plateau
void initialisation(herbe h,mouton m,loup l,sable sand,	monde world[10][10])
{
	

	etreVivant no;
	for(int i=0; i<10; i++)//initialisation a sable^^ on creer un desert
	{
		for(int j=0; j<10; j++)
		{
			world[i][j].ev1 = sand;
			world[i][j].ev2 = no;
			world[i][j].ev3 = no;
		}
	}
    int nbmouton = 10;
    int nbloup = 10;
    int nbherbe = 10;
	int x, y;

	

	for (int i = 0; i < nbherbe; i++)//position aléatoire de l'herbe
	{
		
		//herbe
		h.pos.x = rand()%10;

		h.pos.y = rand()%10;

		world[x][y].ev1 = h;
	}

	for (int i = 0; i < nbmouton; i++)//position aléatoire des moutons
	{
		//mouton
		m.pos.x = rand()%10;// on charge sa position ds la liste
		m.pos.y = rand()%10;
		world[x][y].ev2 =  m;// on le place ds le tableau
		m.pos.ev = 2;
	}

	for (int i = 0; i < nbloup; i++)//position aléatoire des loups
	{
		//loup
		l.pos.x = rand()%10;
		l.pos.y = rand()%10;
		if(world[x][y].ev2.type == "no")//test si il y a de la place
		{
			world[x][y].ev2 =  l;// on le place ds le tableau
			l.pos.ev = 2;
		}
		else
		{
			world[x][y].ev3 =  l;// sinon on le met après
			l.pos.ev = 3;
		}
	}
	affichage(world);
}

void majSelsMineraux(herbe h, sable sand, monde world[10][10])
{
	for( int i =0; i < 10; i++)
	{
		for( int j= 0; j< 10; j++)
		{
			if(world[i][j].selsMineraux != 0)
			{
				world[i][j].selsMineraux -=1;//on enleve 1 selmineral par tour
			}
			if( world[i][j].selsMineraux != 0 && world[i][j].ev1.type =="sable")
			{
				world[i][j].ev1 = h;
			}
			if( world[i][j].selsMineraux == 0 && world[i][j].ev1.type =="herbe")
			{
				world[i][j].ev1 = sand;
			}
			if( world[i][j].ev1.type == "herbe")
			{
				world[i][j].selsMineraux -=1;//on enleve 1 selmineral pour l'herbe
			}
		}
	}
}
