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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
| bool deplacejoueur(int ch, SMap &Map, Joueur &joueur, list<Enemy> &monstre, Player &tidus, map<Position, string> &maplist, bool &change)
{
bool exit = false;
TOUCHE touche;
if(ch == KEY_UP)
touche = haut;
else if( ch == KEY_DOWN)
touche == bas;
else if( ch == KEY_RIGHT)
touche = droite;
else if( ch == KEY_LEFT)
touche = gauche;
else if( ch == 27)
exit = true;
if(exit == false)
{
Map.tileremplace(joueur);
Deplacement deplacement = computeDeplacement(joueur.x(), joueur.y(), Map, touche);
joueur.move(deplacement);
if(Map.tileAt(joueur.x(), joueur.y()) == '_')
{
cout << "teleporteur" << endl;
cout << joueur.x() << " " << joueur.y() << endl;
Position posgamer = Map.gamerNextPosition(joueur.x(), joueur.y());
cout << posgamer.x() << " " << posgamer.y() << endl;
//Teleport tele(joueur);
Position posmap = Map.nextMap(joueur.x(), joueur.y());
cout << posmap.x() << " " << posmap.y() << endl;
auto it = maplist.find(Position(posmap.x(),posmap.y()));
loadMap(Map, (*it).second );
joueur.changepos(posgamer.x(), posgamer.y());
cout << joueur.x() << " " << joueur.y() <<endl;
//Joueur joueur(posgamer.x(), posgamer.y());
//Map.tilegamer(joueur);
//auto it = maplist.find(Position())
//loadMap(Map.nextMap(joueur.x(), joueur.y()));
//tele(Map.gamerNextPosition(joueur.x(), joueur.y()));
}
else if(Map.tileAt(joueur.x(), joueur.y()) == 'C')
{
cout << "coffre" << endl;
string contenue = Map.coffreContaint(joueur.x(), joueur.y());
cout << contenue << endl;
modiffichier(Map, joueur.x(), joueur.y(), change);
change = true;
Map.tilecoffre(joueur);
Deplacement dep = computeDeplacement(joueur.x(), joueur.y(), Map, bas);
joueur.move(dep);
}
else if(Map.tileAt(joueur.x(), joueur.y()) == 'M')
{
Map.monstre.clear();
srand(time(NULL));
int nbmonstre = 0;
while(nbmonstre == 0)
{
nbmonstre = rand() % 6;
}
string filename = Map.title + "_monstre" + ".txt";
cout << "nombre monstre " << nbmonstre << " " << "nom fichier " << filename << endl;
for(int i = 0; i < nbmonstre; i++)
{
chargemonstre(Map, filename, i);
}
int xp = 0;
int argent = 0;
for(int i = 0; i < nbmonstre; i++)
{
cout << "monstre " << i <<endl;
auto it = Map.monstre.find(i);
cout << it->second.nom << " " << it->second.hp <<" "<< it->second.mp << " " <<
it->second.type << " " << it->second.exp << " " << it->second.gold << endl;
monstre.push_back(Enemy(it->second.nom, it->second.hp, it->second.mp, it->second.type, it->second.exp, it->second.gold,
it->second.force, it->second.esprit, it->second.magie, it->second.constitution, it->second.rapidite,
it->second.precision, it->second.esquive));
//ennemi.push_back(Enemy(it->second.nom, it->second.hp, it->second.mp, it->second.type, it->second.exp, it->second.gold));
xp = xp + it->second.exp;
argent = argent + it->second.gold;
}
list<Enemy>::iterator it;
for(it = monstre.begin(); it != monstre.end(); it++)
{
//cout << *it1 << endl;
}
while(nbmonstre != 0)
{
int choix = 0;
cout << "entrer choix monstre " << endl;
cin >> choix;
it = monstre.begin();
advance (it, choix-1);
tidus.attaquer(*it);
/*for(int i = 0; i < nbmonstre; i++)
{
monstre[i].IA(tidus);
}*/
for(it = monstre.begin(); it != monstre.end(); ++it)
{
bool vivant = it->est_vivant();
if(vivant == false)
{
it = monstre.erase(it);
nbmonstre--;
}
else
it->IA(tidus);
}
tidus.afficherinfo();
bool vivant = tidus.est_vivant();
if(vivant == false)
{
tidus.~Player();
return 0;
}
if(nbmonstre != 0)
{
for(it = monstre.begin(); it != monstre.end(); it++)
it->afficherinfo();
}
/*for(int i = 0; i < nbmonstre; i++)
{
monstre[i].afficherinfo();
bool alive = monstre[i].est_vivant();
if(alive == false)
{
monstre[i].~Enemy();
nbmonstre--;
}
}*/
}
}
return false;
}
else
return true;
} |
Partager