// Dictionary.h: interface for the Dictionary class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_DICTIONARY_H__7E288ACB_9241_45F7_948E_521D5AF1EC8D__INCLUDED_)
#define AFX_DICTIONARY_H__7E288ACB_9241_45F7_948E_521D5AF1EC8D__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#pragma warning(disable: 4786)
#include<vector>
#include <map>
#include <string>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <ctime>
#include <cstdlib>

using namespace std;

typedef vector<string> Family;
//typedef multimap<string, string>::iterator Iterator;
//typedef pair <string, string> MonPair;

class Dictionary  
{
public:
	Dictionary();
    void ajouterMot(const std::string &inMot);
	void readFile(string name);
	void readModule(istream& inStream);
	void shuffle();

	virtual ~Dictionary();
//private:
	vector<Family> myDic;
	Family myFamily;
	Family myHint;
	string front;
	string top;
	string back;
	string bottom;
	string hint;


};

Dictionary::Dictionary()
{
	srand ( time(NULL) );
}

Dictionary::~Dictionary()
{

}


void Dictionary::ajouterMot(const std::string &inMot)
{  
   
   if(inMot == "end")
   {
	   myDic.push_back(myFamily);
   }
   else
   {
	   myFamily.push_back(inMot);
   }

}

void Dictionary::readModule(istream& inStream)
{
	
		string lMot;
		while(inStream >> lMot)
		{
		   if(lMot == "begin")
		   {
			   if(!myFamily.empty()) myFamily.clear();
			   inStream>>lMot;
			   for(int i=0;i<lMot.size();i++)
			   {
				   if(lMot[i]=='-') lMot[i]=' ';
			   }
			   myHint.push_back(lMot);

		   }
		   else ajouterMot(lMot);
		  
		}
}
void Dictionary::readFile(string name)
{
	ifstream lStream(name.c_str());
    if(lStream.is_open())
	{
	  readModule(lStream);//cout<<"2"<<endl;
	}
	else
	{
		cerr<<"error"<<endl;
		cout<<name<<endl;
		exit(0);
	}
	lStream.close();
}

void Dictionary::shuffle()
{

	int randDic = rand()% myDic.size();
	int randFam = rand()% (myFamily.size()-4);


	front = myDic[randDic][randFam];
	top = myDic[randDic][randFam+1];
	back = myDic[randDic][randFam+2];
	bottom = myDic[randDic][randFam+4];
	hint = myHint[randDic];

	cout<<front<<endl<<top<<endl<<back<<endl<<bottom<<endl;

}
#endif // !defined(AFX_DICTIONARY_H__7E288ACB_9241_45F7_948E_521D5AF1EC8D__INCLUDED_)
