Skip to content

Instantly share code, notes, and snippets.

@gonzalowtf
Created September 4, 2012 13:18
Show Gist options
  • Save gonzalowtf/3621088 to your computer and use it in GitHub Desktop.
Save gonzalowtf/3621088 to your computer and use it in GitHub Desktop.
intento de juego de ahorcado
//ahorcado
#include<stdio.h>
#include<iostream.h>//se utilizaran de esta las funciones cout y cin
#include<conio.h>// text color y gotoxy(); y getch();
#include<stdlib.h> //srand() y rand()
#include<ctype.h>// toupper y isalpha
#include<string.h> //strcpy strcmp strien
char palabras[4][10], palabra[10], letra, respuesta[10];
int main(int argc, char* argv[])
{
int i,j, longitud,intentos,y;
y=0;
intentos=0;
do{
strcpy(palabras[0], "ARGENTINA");
strcpy(palabras[1], "ESCLEROSIS");
strcpy(palabras[2], "INYECCION");
strcpy(palabras[3], "CANCER");
for(i=0;i<26;i++){
gotoxy(i*2+18,7);
textcolor(i+1);
cprintf("%c",65+1); //porque a partir de 65 se encuentran las letras de la a a la z
}
srand(time(0)); // para que no se repitan las mismas palabras al terminar el juego
j=0+rand()%4;
strcpy(palabra,palabra[j]);
longitud =strien(palabra);
for(i=0;i<longitud;i++){
gotoxy(25+i*4,19);
cprintf("_");
}
do{
gotoxy(25,4);
textcolor(10);
cprintf("BIENVENIDOS AL JUEGO DEL AHORCADO");
gotoxy(25,9);
cprintf("ADIVINA LA PALABRAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
gotoxy(28,12);
cprintf("introduzca una letra======>");
do{
letra=toupper(getch());
}while(!isalpha(letra));
gotoxy(intentos+10,22);
cprintf("%c",letra);
gotoxy(25,15);
cprintf("el numero de intentos es 20 y llevas: [%d]",intentos+1);
for(i=1;i<=longitud;i++){
if(letra==palabra[i]){
gotoxy(29+i*4,18);
cprintf("%c",letra);
respuesta[i]=letra;
}
y=strcmp(palabra,respuesta);
if(y==0){
gotoxy(25,23);
cprintf("GANASTE! :D");
}
intentos++;
}while(intentos<20 && y!=0);
if(intentos==20){
gotoxy(26,23);
cprintf("INCORRECTO, LA PALABRA ERA=====> %s",palabra );
}
gotoxy(26,25);
cprintf("QUIERES JUGAR DE NUEVO? (S/N)");
cin>>letra;
fgetc(stdin);
fgetc(stdin);
}while(letra!= 'n');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment