main.cpp 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. #include <iostream>
  2. #include <fstream>
  3. #include <ctime>
  4. #include <cstdlib>
  5. #include <string>
  6. using namespace std;
  7. int main()
  8. {
  9. cout << "Bienvenue dans le programme de baston développé par du mais !!! XD" << endl;
  10. /// Initialisation
  11. // Initialisation du random
  12. srand(time(0));
  13. // Tableau de caractéristiques
  14. int Caracteristique[2][4]; // [joueur][caracteristique]
  15. /*
  16. Caracteristique == Vitesse
  17. Caracteristique == Defense en %
  18. Caracteristique == Vie
  19. Caracteristique == Attaque
  20. */
  21. // Chaines de caracteres
  22. string nomPerso1;
  23. string nomPerso2;
  24. string phraseDeVictime;
  25. string nomPari;
  26. // Variables
  27. int nbRand1;
  28. int taille;
  29. char lettre;
  30. const char refe('-');
  31. // Ouverture du fichier des noms
  32. ifstream monFlux("Perso.txt");
  33. monFlux.seekg(0, ios::end);
  34. taille = monFlux.tellg() ;
  35. /// Choix des noms
  36. // Joueur 1
  37. nbRand1 = rand () % (taille-7);
  38. monFlux.seekg(nbRand1, ios::beg);
  39. do{
  40. monFlux.seekg(0, ios::cur);
  41. monFlux.get(lettre);
  42. } while(lettre != refe);
  43. getline( monFlux, nomPerso1 );
  44. cin.clear();
  45. // Joueur 2
  46. nbRand1 = rand () % (taille-7);
  47. monFlux.seekg(nbRand1, ios::beg);
  48. do{
  49. monFlux.seekg(0, ios::cur);
  50. monFlux.get(lettre);
  51. } while(lettre != refe);
  52. getline( monFlux, nomPerso2 );
  53. cin.clear();
  54. monFlux.close();
  55. // Affichage de début
  56. cout << "Les paris sont ouverts !!!" << endl;
  57. cout << nomPerso1;
  58. cout << "1 va se battre contre ";
  59. cout << nomPerso2;
  60. cout << "2" << endl << endl;
  61. /// Pari
  62. // Choix joueur
  63. do{
  64. cout << "Sur qui voulez-vous parier ?" << endl;
  65. cin >> nomPari;
  66. if( nomPari != "1" && nomPari != "2" ) {
  67. cout << "Ce nombre ne correspond a aucuns des combattants..." << endl;
  68. }
  69. } while (nomPari != "1" && nomPari != "2");
  70. // Choix des caractéristiques
  71. for (int i=0; i<4;i++){
  72. Caracteristique[0][i] = rand() % 21;
  73. }
  74. for (int i=0; i<4;i++){
  75. Caracteristique[1][i] = rand() % 21;
  76. }
  77. //Cheat Perso
  78. if(nomPerso1 == "CeciEstCoderEnC++ParMariusEtBruce" || nomPerso1 == "°°°°°°°°"){
  79. Caracteristique[0][0] = 666;
  80. Caracteristique[0][1] = 666;
  81. Caracteristique[0][2] = 666;
  82. Caracteristique[0][3] = 666;
  83. }
  84. if(nomPerso2 == "CeciEstCoderEnC++ParMariusEtBruce" || nomPerso2 == "°°°°°°°°"){
  85. Caracteristique[1][0] = 666;
  86. Caracteristique[1][1] = 666;
  87. Caracteristique[1][2] = 666;
  88. Caracteristique[1][3] = 666;
  89. }
  90. //Affichage des caractéristiques
  91. cout << endl;
  92. cout << "Stats pour " << nomPerso1 << endl;
  93. cout << endl;
  94. cout << "Vitesse : " << Caracteristique[0][0] << endl;
  95. cout << "Defense : " << Caracteristique[0][1] << endl;
  96. cout << "Vie : " << Caracteristique[0][2] << endl;
  97. cout << "Attaque : " << Caracteristique[0][3] << endl;
  98. cout << endl;
  99. cout << "Stats pour " << nomPerso2 << endl;
  100. cout << endl;
  101. cout << "Vitesse : " << Caracteristique[1][0] << endl;
  102. cout << "Defense : " << Caracteristique[1][1] << endl;
  103. cout << "Vie : " << Caracteristique[1][2] << endl;
  104. cout << "Attaque : " << Caracteristique[1][3] << endl;
  105. cout << endl;
  106. cout << nomPerso1 << ": Prepare toi a mourrir !" << endl;
  107. cout << nomPerso2 << ": Tu mourra avant moi !" << endl;
  108. cout << endl;
  109. /// Boucle de combat
  110. int Ordre = 0;
  111. while(Caracteristique[1][2] > 0 && Caracteristique[0][2] > 0)
  112. {
  113. int Prems = 0;
  114. do
  115. {
  116. if ( (Caracteristique[0][0]<Caracteristique[1][0] && Ordre == 0) || Ordre == 2 )
  117. {
  118. int Degats1 = Caracteristique[1][3] - Caracteristique[0][1]*0.4;
  119. if (Degats1 <= 0)
  120. {
  121. Degats1 = 1 ;
  122. }
  123. Caracteristique[0][2] = Caracteristique[0][2] - Degats1;
  124. Prems = 1;
  125. cout << nomPerso2 << " inflige " << Degats1 << " a " << nomPerso1 << endl;
  126. if (Caracteristique [0][2] <= 0)
  127. {
  128. Caracteristique [0][2] = 0;
  129. }
  130. cout << "Il reste " << Caracteristique [0][2] << " PV a " << nomPerso1 << endl;
  131. Ordre = 1;
  132. }
  133. else if ((Caracteristique[0][0]>Caracteristique[1][0] && Ordre == 0) || Ordre == 1)
  134. {
  135. int Degats1 = Caracteristique[0][3] - Caracteristique[1][1]*0.4;
  136. if (Degats1 <= 0)
  137. {
  138. Degats1 = 1 ;
  139. }
  140. Caracteristique[1][2] = Caracteristique[1][2] - Degats1;
  141. Prems = 1;
  142. cout << nomPerso1 << " inflige " << Degats1 << " a " << nomPerso2 << endl;
  143. if (Caracteristique [1][2] <= 0)
  144. {
  145. Caracteristique [1][2] = 0;
  146. }
  147. cout << "Il reste " << Caracteristique [1][2] << " PV a " << nomPerso2 << endl;
  148. Ordre = 2 ;
  149. }
  150. else
  151. {
  152. int nki = rand() % 2;
  153. Caracteristique[nki][0] =- 1;
  154. }
  155. } while(Prems == 0);
  156. }
  157. // Choix de la mort
  158. ifstream monCul("Phrases.txt");
  159. monCul.seekg(0,ios::end);
  160. taille = monCul.tellg() ;
  161. nbRand1 = rand () % (taille-11);
  162. monCul.seekg(nbRand1, ios::beg);
  163. do{
  164. monCul.seekg(0, ios::cur);
  165. monCul.get(lettre);
  166. } while(lettre != refe);
  167. getline(monCul,phraseDeVictime);
  168. // Test de la mort pour affichage
  169. if( Caracteristique[1][2] <= 0 ){
  170. cout << nomPerso1 << phraseDeVictime << nomPerso2 << endl;
  171. if(nomPari == "1"){
  172. cout << "Vous avez reussi votre pari ! Bravo !" << endl;
  173. }
  174. else{
  175. cout << "Vous avez perdu votre pari... Dommage..." << endl;
  176. }
  177. }
  178. else{
  179. cout << nomPerso2 << phraseDeVictime << nomPerso1 << endl;
  180. if(nomPari == "2"){
  181. cout << "Vous avez reussi votre pari ! Bravo !" << endl;
  182. }
  183. else{
  184. cout << "Vous avez perdu votre pari... Dommage..." << endl;
  185. }
  186. }
  187. monCul.close();
  188. return 0;
  189. }