1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
| void chargemonstre(SMap & Map, string filename, int index)
{
cout << "chargement monstre" << endl;
ifstream ifs(filename);
int ligne = 0;
while(!ifs.eof())
{
char c = ifs.get();
if(c == '\n')
{
ligne++;
}
}
//cout << "ligne " << ligne << endl;
/*std::tr1::mt19937 gen(time(0));
std::tr1::uniform_int <int> a(1,ligne);
int lignechoisi = a(gen);*/
//srand(time(0));
int lignechoisi = 0;
lignechoisi = (rand() % ligne);
cout << "ligne choisi " << lignechoisi << endl;
/* ifs.clear();
ifs.seekg(0, ios::beg);
int pos = ifs.tellg();
cout << "position " << pos << endl;*/
ifs.close();
ifs.open(filename);
// ifstream ifs(filename);
//lignechoisi--;
while(lignechoisi > 0)
{
//cout << "entrer 2eme boucle" << endl;
char c = ifs.get();
//cout << c << endl;
if(c == '\n')
{
//cout << c << " trouver" << endl;
lignechoisi--;
//cout << "ligne " << lignechoisi << endl;
}
/*string nom;
getline(ifs, nom);
lignechoisi--;
cout << nom << endl;*/
}
string nom;
int hp;
int mp;
string type;
int exp;
int gold;
//cout << "remplissage" << endl;
ifs>>nom>>hp>>mp>>type>>exp>>gold;
//cout << nom << " " << hp << " " << mp << " " <<
// type << " " << exp << " " << gold << endl;
//cout << "fin remplissage" << endl;
//Map.monstre.insert(std::make_pair(Position(joueur.x(), joueur.y()), SMonstre(nom, hp, mp, type, exp, gold)));
Map.monstre.insert(std::make_pair(int(index), SMonstre(nom, hp, mp, type, exp, gold)));
} |
Partager