Guest User

Untitled

a guest
Nov 24th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.97 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <ctime>
  4. #include <stdio.h>
  5. #include <cmath>
  6. #include <string>
  7. using std::cout;
  8. using std::endl;
  9. using std::cin;
  10. using std::string;
  11. string palabra_original;
  12. string palabra_mostrar;
  13. int intentos;
  14. void mostrar();
  15. void ingresar (char x);
  16. void inicializar();
  17. char a=92;
  18. int horca(int intentos){
  19. if (intentos==9)
  20. {
  21. cout << " __________" << endl;
  22. cout << "|" << endl;
  23. cout << "|" << endl;
  24. cout << "|" << endl;
  25. cout << "|" << endl;
  26. cout << "|" << endl;
  27. cout << "|" << endl;
  28. cout << "|___________" << endl;
  29. }
  30. if (intentos==8)
  31. {
  32. cout << " __________" << endl;
  33. cout << "|" << endl;
  34. cout << "| 0" << endl;
  35. cout << "|" << endl;
  36. cout << "|" << endl;
  37. cout << "|" << endl;
  38. cout << "|" << endl;
  39. cout << "|___________" << endl;
  40. }
  41. if (intentos==7)
  42. {
  43. cout << " __________" << endl;
  44. cout << "|" << endl;
  45. cout << "| 0" << endl;
  46. cout << "| |" << endl;
  47. cout << "|" << endl;
  48. cout << "|" << endl;
  49. cout << "|" << endl;
  50. cout << "|___________" << endl;
  51. }
  52. if (intentos==6)
  53. {
  54. cout << " __________" << endl;
  55. cout << "|" << endl;
  56. cout << "| 0" << endl;
  57. cout << "| _|" << endl;
  58. cout << "|" << endl;
  59. cout << "|" << endl;
  60. cout << "|" << endl;
  61. cout << "|___________" << endl;
  62. }
  63. if (intentos==5)
  64. {
  65. cout << " __________" << endl;
  66. cout << "|" << endl;
  67. cout << "| 0" << endl;
  68. cout << "| _|_" << endl;
  69. cout << "|" << endl;
  70. cout << "|" << endl;
  71. cout << "|" << endl;
  72. cout << "|___________" << endl;
  73. }
  74. if (intentos==4)
  75. {
  76. cout << " __________" << endl;
  77. cout << "|" << endl;
  78. cout << "| 0" << endl;
  79. cout << "| _|_" << endl;
  80. cout << "| |" << endl;
  81. cout << "|" << endl;
  82. cout << "|" << endl;
  83. cout << "|___________" << endl;
  84. }
  85. if (intentos==3)
  86. {
  87. cout << " __________" << endl;
  88. cout << "|" << endl;
  89. cout << "| 0" << endl;
  90. cout << "| _|_" << endl;
  91. cout << "| |" << endl;
  92. cout << "| |" << endl;
  93. cout << "|" << endl;
  94. cout << "|___________" << endl;
  95. }
  96. if (intentos==2)
  97. {
  98. cout << " __________" << endl;
  99. cout << "|" << endl;
  100. cout << "| 0" << endl;
  101. cout << "| _|_" << endl;
  102. cout << "| |" << endl;
  103. cout << "| |" << endl;
  104. cout << "| _|" << endl;
  105. cout << "|___________" << endl;
  106. }
  107. if (intentos==1)
  108. {
  109. cout << " __________" << endl;
  110. cout << "|" << endl;
  111. cout << "| 0" << endl;
  112. cout << "| _|_" << endl;
  113. cout << "| |" << endl;
  114. cout << "| |" << endl;
  115. cout << "| _|_" << endl;
  116. cout << "|___________" << endl;
  117. }
  118. if (intentos==0)
  119. {
  120. cout << " __________" << endl;
  121. cout << "| |" << endl;
  122. cout << "| 0" << endl;
  123. cout << "| _|_" << endl;
  124. cout << "| |" << endl;
  125. cout << "| |" << endl;
  126. cout << "| _|_" << endl;
  127. cout << "|___________" << endl;
  128. }
  129.  
  130. }
  131. int main(){
  132. cout << "Welcome to the best hangedman of the history" << endl;
  133. cout << "Here you can learn some german, because that the purpose of this game" << endl;
  134. cout << "that´s why all the words here are in german composed by an article and a noun" << endl;
  135. cout << "Only one letter is accepted per attempt" << endl;
  136. inicializar();
  137. mostrar();
  138. while (intentos>0 && palabra_mostrar!=palabra_original)
  139. {
  140. char x=0;
  141. cout<< "Please enter one the letter" << endl;
  142. cin>> x;
  143. ingresar(x);
  144. mostrar();
  145. if (intentos>=0 && palabra_mostrar==palabra_original)
  146. {
  147. cout << "Congrats!! you win" << endl;
  148. }
  149. if (intentos==0) cout << "Sorry you have lost, the word was: " << palabra_original << endl;
  150. }
  151.  
  152. }
  153.  
  154. void mostrar()
  155. {
  156. cout << "Attempts: " << intentos << endl;
  157. cout << palabra_mostrar << endl;
  158. }
  159. void inicializar()
  160. {
  161. const char* listadepalabras[6] = {"das ei","der stuhl", "der tisch","das kinder","die frau",'\0'};
  162. char numero;
  163. srand(time(NULL));
  164. numero=rand()%6;
  165. intentos=9;
  166. palabra_original = listadepalabras[numero];
  167. palabra_mostrar = palabra_original;
  168. for (int i=0 ; i<palabra_original.length(); i++){
  169. if (palabra_original[i]>= 'A' && palabra_original[i]<= 'Z'){
  170. palabra_original[i]+=32;
  171. }
  172. }
  173. for (int i=0 ; i<palabra_original.length(); i++){
  174. if (palabra_original[i]>= 'a' && palabra_original[i]<= 'z'){
  175. palabra_mostrar[i]= '_';
  176. }
  177. }
  178. }
  179. void ingresar(char x)
  180. {
  181. bool perdividas=true;
  182. for (int i=0; i<palabra_original.length(); i++)
  183. {
  184. if (x==palabra_original[i])
  185. {
  186. perdividas=false;
  187. palabra_mostrar[i]=x;
  188. }
  189. }
  190. if (perdividas==true)
  191. {
  192. intentos--;
  193. horca(intentos);
  194. }
  195. }
Add Comment
Please, Sign In to add comment