#include "Structure_entity.hpp" #include void entity::afficher_aide() { for (auto& action_actuelle : liste_actions) { if (action_actuelle.avaible == true) { std::cout << action_actuelle.action_name << " : " << action_actuelle.description << std::endl; } } } bool entity::test_mort() { return PV <= 0; } // Détermine si une entité est mort void entity::message_mort() { std::cout << "PV restants : " << PV << std::endl << std::endl; if (test_mort() == true) { std::cout << entity_name << " est mort." << std::endl; } else { std::cout << "Tour suivant !" << std::endl; } } // Permet d'afficher un message de mort en fonction du nom de l'entité void entity::remise_a_zero_des_PV() { if (test_mort() == true && PV < 0) { PV = 0; } message_mort(); } // Remet les PV d'une entité à zéro si ils sont négatifs à l'aide de la fonction test_mort void entity::fonction_mort() { remise_a_zero_des_PV(); std::cout << std::endl; } // Regroupe les fonctions de test_mort à message_mort et gère la mort d'une entité void entity::assaut(entity& cible) { std::random_device rd; std::mt19937 gen(rd()); std::uniform_int_distribution facteur_aleatoire(1, 100); int Tentative{ 1 }; int Dommages{ ATT - cible.DEF }; if (Dommages <= 0) { Dommages = 1; } std::cout << entity_name << " attaque " << cible.entity_name << "." << std::endl; Tentative = facteur_aleatoire(gen); if (Tentative <= PRECISION) { std::cout << "Dégâts infligés : " << Dommages << std::endl; cible.PV -= Dommages; } else { std::cout << entity_name << " rate sa cible" << std::endl; } } // Permet à une entité d'attaquer une cible void entity::assaut_renforce(entity& cible) { std::random_device rd; std::mt19937 gen(rd()); std::uniform_int_distribution facteur_aleatoire(1, 100); int Tentative{ 1 }; int Dommages{ (ATT * 2) - cible.DEF }; if (Dommages <= 0) { Dommages = 1; } std::cout << entity_name << " attaque " << cible.entity_name << "." << std::endl; Tentative = facteur_aleatoire(gen); if (Tentative <= PRECISION * 0.75) { std::cout << "Dégâts infligés : " << Dommages << std::endl; cible.PV -= Dommages; } else { std::cout << entity_name << " rate sa cible" << std::endl; } } // Permet à une entité d'attaquer une cible std::string entity::choix_actions_menu(entity& joueur, std::vector& liste_ennemis, int& niveau) { std::cout << "MENU PRINCIPAL" << std::endl << std::endl; std::cout << "Sélectionne une action parmi les suivantes :" << std::endl; std::cout << "combattre" << std::endl; std::cout << "sauvegarder" << std::endl; std::cout << "charger" << std::endl; std::cout << "quitter" << std::endl; std::cout << "aide" << std::endl; std::string choix{ "" }; bool choix_correct{ false }; action action_trouvee{ "default" }; auto cherche_action { [&action_trouvee](std::string& choix, std::vector& actions_d_entite) -> bool { bool trouve{ false }; for (auto& action : actions_d_entite) { if (choix == action.action_name && action.avaible == true) { trouve = true; action_trouvee = action; break; } } return trouve; } }; auto execution_fonction { [&joueur, &liste_ennemis, &niveau, &action_trouvee, &choix]() -> void { if (choix == "combattre") { if (niveau > 4) { std::cout << "Tu as terminé le jeu, redémarre pour recommencer ou charge la sauvegarde." << std::endl; std::cout << std::endl; } else { action_trouvee.executer_fonction(joueur, liste_ennemis[niveau], niveau); } } else if (choix == "sauvegarder" || choix == "charger") { action_trouvee.executer_fonction(niveau); } else { action_trouvee.executer_fonction(); } } }; entree_securisee(choix, cherche_action, execution_fonction, liste_actions); return choix; } std::string entity::comportement() { std::string action_choisie{ "" }; std::random_device choix_du_bot; std::mt19937 gen(choix_du_bot()); std::uniform_int_distribution facteur_aleatoire(1, 5); int choix{ facteur_aleatoire(gen) }; std::cout << std::boolalpha << (PV <= PV_initiaux / 2) << std::endl << (special.avaible == true) << std::endl; if (PV <= PV_initiaux / 2 && special.avaible == true) { action_choisie = "spécial"; } else if (choix >= 1 && choix <= 4) { action_choisie = "attaquer"; } else if (choix == 5) { action_choisie = "défense"; } return action_choisie; } void entity::choix_actions_combat(entity& cible) { std::cout << "Sélectionne une action parmi les suivantes :" << std::endl; std::cout << "attaquer" << std::endl; std::cout << "spécial" << std::endl; std::cout << "défense" << std::endl; std::cout << "aide" << std::endl; std::string choix { "" }; bool choix_correct{ false }; action action_trouvee { "default" }; auto cherche_action { [&action_trouvee](std::string& choix, std::vector& actions_d_entite) -> bool { bool trouve{ false }; for (auto& action : actions_d_entite) { if (choix == action.action_name && action.avaible == true) { trouve = true; action_trouvee = action; break; } } return trouve; } }; auto execution_fonction { [&cible, &action_trouvee, &choix]() -> void { if (choix == "aide" || choix == "défense") { action_trouvee.executer_fonction(); } else { action_trouvee.executer_fonction(cible); } } }; entree_securisee(choix, cherche_action, execution_fonction, liste_actions); } // Permet à une entité de choisir une action void entity::fonction_a_moi_de_jouer(entity& cible) { std::cout << "Au tour de " << entity_name << std::endl; if (Classe == "joueur") { choix_actions_combat(cible); } else if (Classe == "bot") { std::string action_choisie{ comportement() }; std::cout << action_choisie << std::endl; for (auto &action : liste_actions) { if (action.action_name == action_choisie && action_choisie == "défense") { action.executer_fonction(); } else if (action.action_name == action_choisie && action_choisie == "attaquer") { action.executer_fonction(cible); } else if (action.action_name == action_choisie && action_choisie == "spécial") { action.executer_fonction(cible); } } } } // Gère le tour d'une entité