elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Introducción a la Factorización De Semiprimos (RSA)


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación C/C++ (Moderadores: Eternal Idol, Littlehorse, K-YreX)
| | |-+  Ayuda con juego de adivinar palabras
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Ayuda con juego de adivinar palabras  (Leído 2,235 veces)
Beginner Web


Desconectado Desconectado

Mensajes: 634


youtu.be/0YhflLRE-DA


Ver Perfil
Ayuda con juego de adivinar palabras
« en: 14 Junio 2018, 04:16 am »

Quisiera que alguien diga como tengo que hacer para que cada vez que cometo un error o acierto una letra se vaya limpiando la pantalla con system("cls") de manera correcta y se vaya como actualizando el juego del ahorcado y no mostrando todo secuencialmente como lo hace mi programa  ;-)

Código
  1. #include <iostream>
  2. #include <string.h>
  3. #include <time.h>
  4.  
  5. using namespace std;
  6.  
  7. void inicio();
  8. void primer_error();
  9. void segundo_error();
  10. void tercer_error();
  11. void cuarto_error();
  12. void quinto_error();
  13. void jugar();
  14. void rellenar(string n);
  15. void intentos(int intento);
  16.  
  17. int main(){
  18. int opcion;
  19. srand(time(NULL));
  20. do{
  21. cout << "1. JUGAR" << endl;
  22. cout << "2. SALIR" << endl;
  23. cin >> opcion;
  24. switch(opcion){
  25. case 1: jugar(); break;
  26. case 2: cout << "HASTA LUEGO" << endl; break;
  27. default: cout << "OPCION INCORRECTA, Intente de nuevo" << endl;
  28. }
  29. }while(opcion!=2);
  30. system("pause");
  31. return 0;
  32. }
  33.  
  34. void inicio()
  35. {
  36. cout << "**********" << endl;
  37. cout << "*           " << endl;
  38. cout << "*           " << endl;
  39. cout << "*           " << endl;
  40. cout << "*           " << endl;
  41. cout << "*           " << endl;
  42. cout << "*           " << endl;
  43. }
  44.  
  45. void primer_error()
  46. {
  47. cout << "**********" << endl;
  48. cout << "*        |  " << endl;
  49. cout << "*           " << endl;
  50. cout << "*           " << endl;
  51. cout << "*           " << endl;
  52. cout << "*           " << endl;
  53. cout << "*           " << endl;
  54. }
  55.  
  56. void segundo_error()
  57. {
  58. cout << "**********" << endl;
  59. cout << "*        |  " << endl;
  60. cout << "*        O  " << endl;
  61. cout << "*           " << endl;
  62. cout << "*           " << endl;
  63. cout << "*           " << endl;
  64. cout << "*           " << endl;
  65. }
  66.  
  67. void tercer_error()
  68. {
  69. cout << "**********" << endl;
  70. cout << "*        |  " << endl;
  71. cout << "*        O  " << endl;
  72. cout << "*       /|\\" << endl;
  73. cout << "*           " << endl;
  74. cout << "*           " << endl;
  75. cout << "*           " << endl;
  76. }
  77.  
  78. void cuarto_error()
  79. {
  80. cout << "**********" << endl;
  81. cout << "*        |  " << endl;
  82. cout << "*        O  " << endl;
  83. cout << "*       /|\\" << endl;
  84. cout << "*        A  " << endl;
  85. cout << "*       / \\" << endl;
  86. cout << "*           " << endl;
  87. }
  88.  
  89. void quinto_error()
  90. {
  91. cout << "**********   " << endl;
  92. cout << "*        |   " << endl;
  93. cout << "*        O   " << endl;
  94. cout << "*       /|\\ " << endl;
  95. cout << "*        A   " << endl;
  96. cout << "*       / \\ " << endl;
  97. cout << "*            " << endl;
  98. cout << "     PERDISTE" << endl;
  99. }
  100.  
  101. void jugar()
  102. {
  103. int aleatorio;
  104. string a="OSO", b="PAYASO", c="CUADERNO";
  105.   aleatorio=rand()%3+1;
  106. switch(aleatorio){
  107. case 1: rellenar(a); break;
  108. case 2: rellenar(b); break;
  109. case 3: rellenar(c); break;
  110. }
  111. }
  112.  
  113. void rellenar(string n)
  114. {
  115. int contador=0, aux=0, aux2, MAX=n.length();
  116. char letra, contenedor[MAX];
  117. for(int i=0;i<MAX;i++){
  118. contenedor[i]='_';
  119. }
  120. inicio();
  121. while(contador<5){
  122. aux2=0;
  123. for(int j=0;j<MAX;j++){
  124. cout << contenedor[j] << " ";
  125. }
  126. cout << endl;
  127. cout << "Ingrese letra: ";
  128. cin >> letra;
  129. for(int k=0;k<MAX;k++){
  130. if(letra==n[k] && contenedor[k]=='_'){
  131. contenedor[k]=letra;
  132. aux++;
  133. break;
  134. }
  135. else{
  136. aux2++;
  137. }
  138. }
  139. if(aux==MAX){
  140. cout << "GANASTE! La palabra oculta es: " << n << endl;
  141. break;
  142. }
  143. if(aux2==MAX){
  144. contador++;
  145. intentos(contador);
  146. }
  147. }
  148. }
  149.  
  150. void intentos(int intento)
  151. {
  152. switch(intento){
  153. case 1: primer_error(); break;
  154. case 2: segundo_error(); break;
  155. case 3: tercer_error(); break;
  156. case 4: cuarto_error(); break;
  157. case 5: quinto_error(); break;
  158. }
  159. }
  160.  
  161.  


« Última modificación: 14 Junio 2018, 07:34 am por Beginner Web » En línea

7w7
PiernaDeFelipeCamiroaga

Desconectado Desconectado

Mensajes: 12



Ver Perfil
Re: Ayuda con juego de adivinar palabras
« Respuesta #1 en: 15 Junio 2018, 05:45 am »

El problema es que te faltaban librerías <windows.h> y <stdlib.h> la primera para poder usar el "cls"y la otra para los números aleatorio y use void gotoxy(int x, int y) para otorgar coordenadas a la parte donde ingresas las letras y asi poder sobre escribir en la misma posición y se viera como si se borrara y use los system("cls") para borrar el monito de palo mostrar el siguiente.

No se si me explique bien pero igual te dejo el código "arreglado"

Código
  1. #include <windows.h>
  2. #include <stdlib.h>
  3. #include <iostream>
  4. #include <string.h>
  5. #include <time.h>
  6.  
  7. using namespace std;
  8.  
  9. void inicio();
  10. void primer_error();
  11. void segundo_error();
  12. void tercer_error();
  13. void cuarto_error();
  14. void quinto_error();
  15. void jugar();
  16. void rellenar(string n);
  17. void intentos(int intento);
  18.  
  19. void gotoxy(int x,int y){
  20. HANDLE hcon;
  21. hcon = GetStdHandle(STD_OUTPUT_HANDLE);
  22.  
  23. COORD pos;
  24. pos.X = x;
  25. pos.Y = y;
  26. SetConsoleCursorPosition(hcon,pos);
  27. }
  28.  
  29. int main(){
  30. int opcion;
  31. srand(time(NULL));
  32. do{
  33. cout << "1. JUGAR" << endl;
  34. cout << "2. SALIR" << endl;
  35. cin >> opcion;
  36. system("cls");
  37. switch(opcion){
  38. case 1: jugar(); break;
  39. case 2: cout << "HASTA LUEGO" << endl; break;
  40. default: cout << "OPCION INCORRECTA, Intente de nuevo" << endl;
  41. }
  42. }while(opcion!=2);
  43. system("pause");
  44. return 0;
  45. }
  46.  
  47. void inicio()
  48. {
  49. cout << "**********" << endl;
  50. cout << "*           " << endl;
  51. cout << "*           " << endl;
  52. cout << "*           " << endl;
  53. cout << "*           " << endl;
  54. cout << "*           " << endl;
  55. cout << "*           " << endl;
  56. }
  57.  
  58. void primer_error()
  59. {
  60. system("cls");
  61. cout << "**********" << endl;
  62. cout << "*        |  " << endl;
  63. cout << "*           " << endl;
  64. cout << "*           " << endl;
  65. cout << "*           " << endl;
  66. cout << "*           " << endl;
  67. cout << "*           " << endl;
  68. }
  69.  
  70. void segundo_error()
  71. {
  72. system("cls");
  73. cout << "**********" << endl;
  74. cout << "*        |  " << endl;
  75. cout << "*        O  " << endl;
  76. cout << "*           " << endl;
  77. cout << "*           " << endl;
  78. cout << "*           " << endl;
  79. cout << "*           " << endl;
  80. }
  81.  
  82. void tercer_error()
  83. {
  84. system("cls");
  85. cout << "**********" << endl;
  86. cout << "*        |  " << endl;
  87. cout << "*        O  " << endl;
  88. cout << "*       /|\\" << endl;
  89. cout << "*           " << endl;
  90. cout << "*           " << endl;
  91. cout << "*           " << endl;
  92. }
  93.  
  94. void cuarto_error()
  95. {
  96. system("cls");
  97. cout << "**********" << endl;
  98. cout << "*        |  " << endl;
  99. cout << "*        O  " << endl;
  100. cout << "*       /|\\" << endl;
  101. cout << "*        A  " << endl;
  102. cout << "*       / \\" << endl;
  103. cout << "*           " << endl;
  104. }
  105.  
  106. void quinto_error()
  107. {
  108. system("cls");
  109. cout << "**********   " << endl;
  110. cout << "*        |   " << endl;
  111. cout << "*        O   " << endl;
  112. cout << "*       /|\\ " << endl;
  113. cout << "*        A   " << endl;
  114. cout << "*       / \\ " << endl;
  115. cout << "*            " << endl;
  116. cout << "     PERDISTE" << endl;
  117. }
  118.  
  119. void jugar()
  120. {
  121. int aleatorio;
  122. string a="OSO", b="PAYASO", c="CUADERNO";
  123.   aleatorio=rand()%3+1;
  124. switch(aleatorio){
  125. case 1: rellenar(a); break;
  126. case 2: rellenar(b); break;
  127. case 3: rellenar(c); break;
  128. }
  129. }
  130.  
  131. void rellenar(string n)
  132. {
  133. int contador=0, aux=0, aux2, MAX=n.length();
  134. char letra, contenedor[MAX];
  135. for(int i=0;i<MAX;i++){
  136. contenedor[i]='_';
  137. }
  138. inicio();
  139. while(contador<5){
  140. aux2=0;
  141. for(int j=0;j<MAX;j++){
  142. cout << contenedor[j] << " ";
  143. }
  144. gotoxy(0,8);
  145. cout << endl;
  146. cout << "Ingrese letra: ";
  147. cin >> letra;
  148. for(int k=0;k<MAX;k++){
  149. if(letra==n[k] && contenedor[k]=='_'){
  150. contenedor[k]=letra;
  151. aux++;
  152. break;
  153. }
  154. else{
  155. aux2++;
  156. }
  157. }
  158. if(aux==MAX){
  159. cout << "GANASTE! La palabra oculta es: " << n << endl;
  160. break;
  161. }
  162. if(aux2==MAX){
  163. contador++;
  164. intentos(contador);
  165. }
  166. }
  167. }
  168.  
  169. void intentos(int intento)
  170. {
  171. switch(intento){
  172. case 1: primer_error(); break;
  173. case 2: segundo_error(); break;
  174. case 3: tercer_error(); break;
  175. case 4: cuarto_error(); break;
  176. case 5: quinto_error(); break;
  177. }
  178. }
  179.  


En línea

Beginner Web


Desconectado Desconectado

Mensajes: 634


youtu.be/0YhflLRE-DA


Ver Perfil
Re: Ayuda con juego de adivinar palabras
« Respuesta #2 en: 15 Junio 2018, 23:41 pm »

Muchas gracias @PiernaDeFelipeCamiroaga, era lo que me faltaba  ;-)
En línea

7w7
Rak_Tortuga

Desconectado Desconectado

Mensajes: 2


Ver Perfil
Re: Ayuda con juego de adivinar palabras
« Respuesta #3 en: 18 Junio 2018, 21:49 pm »

Código
  1. #include<stdio.h>
  2. main(){
  3. printf("Hola?");}
  4. // probando publican código xd
  5.  
En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Ayuda filtrando palabras
Programación Visual Basic
hAcKeR92 3 1,645 Último mensaje 10 Febrero 2010, 23:43 pm
por hAcKeR92
Juego de palabras C++ (Sencillo)
Programación C/C++
Danyel_Casvill 0 17,315 Último mensaje 23 Abril 2013, 03:17 am
por Danyel_Casvill
Obtener el porcentaje de oraciones con 1 palabra, 2 palabras, 3 palabras, etc.
Scripting
Wil630 5 4,157 Último mensaje 2 Noviembre 2015, 22:58 pm
por Wil630
juego de adivinar palabras en consola con 3 dificultades
Java
sheiking 1 3,339 Último mensaje 2 Octubre 2018, 01:16 am
por rub'n
ayuda con recursividad juego de adivinar animales
Java
sheiking 0 2,496 Último mensaje 1 Abril 2019, 18:30 pm
por sheiking
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines