Adam asmaca c programlama
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
char kelimeler[][20] = { "AHMET", "MAHMUT", "AYSE", "KALEM", "BILGISAYAR", "MUHENDIS", "ELMA", "CPU", "RAM", "HARDDISK" } ;
char *kelime;
char tahmin[50];
int size;
void kelimeUret()
{
int indis= rand() %10;
kelime= kelimeler[indis] ;
size = strlen(kelime) ;
int i=0;
tahmin[size+1];
while( i<size )
{
tahmin[i] = '-';
i++;
}
tahmin[i]= '\0';
//printf("Kelime : %s \n", kelime ) ;
printf("Harf sayisi : %d \n", size) ;
printf("Tahmin : %s \n", tahmin );
}
int harfKontrol( char harf )
{
int i =0;
int sonuc=0;
while( i<size )
{
char *kPtr, *tPtr;
kPtr= kelime;
tPtr= tahmin;
if( harf == kPtr[i] )
{
tPtr[i] = harf;
sonuc= 1;
}
i++;
}
return sonuc;
}
int sonucKontrol ()
{
int i=0;
int sonuc=1;
printf("\nTahmininiz : " ) ;
while ( i<size )
{
if( tahmin[i]== '-' )
{
sonuc=0;
}
printf(" %c ", tahmin[i] ) ;
i++;
}
printf("\n") ;
return sonuc;
}
void sehpaCiz(int n )
{
system("cls") ;
printf("\n\t\tHANGMAN CHALLENGE \n\n") ;
if( n==2 )
{
printf("\t\t----------\n") ;
}
if( n==3 )
{
printf("\t\t |\n") ;
printf("\t\t |\n") ;
printf("\t\t----------\n") ;
}
if( n==4 )
{
printf("\t\t |\n") ;
printf("\t\t |\n") ;
printf("\t\t |\n") ;
printf("\t\t |\n") ;
printf("\t\t----------\n") ;
}
if( n==5 )
{
printf("\t\t |\n") ;
printf("\t\t |\n") ;
printf("\t\t |\n") ;
printf("\t\t |\n") ;
printf("\t\t |\n") ;
printf("\t\t |\n") ;
printf("\t\t----------\n") ;
}
if( n==6 )
{
printf("\t\t |\n") ;
printf("\t\t |\n") ;
printf("\t\t |\n") ;
printf("\t\t |\n") ;
printf("\t\t |\n") ;
printf("\t\t |\n") ;
printf("\t\t |\n") ;
printf("\t\t |\n") ;
printf("\t\t----------\n") ;
}
if( n==7 )
{
printf("\t\t----------\n") ;
printf("\t\t |\n") ;
printf("\t\t |\n") ;
printf("\t\t |\n") ;
printf("\t\t |\n") ;
printf("\t\t |\n") ;
printf("\t\t |\n") ;
printf("\t\t |\n") ;
printf("\t\t |\n") ;
printf("\t\t----------\n") ;
}
if( n==8 )
{
printf("\t\t----------\n") ;
printf("\t\t | |\n") ;
printf("\t\t O |\n") ;
printf("\t\t |\n") ;
printf("\t\t |\n") ;
printf("\t\t |\n") ;
printf("\t\t |\n") ;
printf("\t\t |\n") ;
printf("\t\t |\n") ;
printf("\t\t----------\n") ;
}
if( n==9 )
{
printf("\t\t----------\n") ;
printf("\t\t | |\n") ;
printf("\t\t O |\n") ;
printf("\t\t /|\\ |\n") ;
printf("\t\t |\n") ;
printf("\t\t |\n") ;
printf("\t\t |\n") ;
printf("\t\t |\n") ;
printf("\t\t |\n") ;
printf("\t\t----------\n") ;
}
if( n==10 )
{
printf("\t\t----------\n") ;
printf("\t\t | |\n") ;
printf("\t\t O |\n") ;
printf("\t\t /|\\ |\n") ;
printf("\t\t | |\n") ;
printf("\t\t / \\ |\n") ;
printf("\t\t |\n") ;
printf("\t\t |\n") ;
printf("\t\t |\n") ;
printf("\t\t----------\n") ;
printf("\t\tASILDINIZ ! \n\n") ;
printf("Aranan kelime : %s \n", kelime) ;
}
}
int main( )
{
printf("\n\t\tHANGMAN CHALLENGE \n\n") ;
srand(time(0)) ;
kelimeUret();
int adet=0, sonuc1, sonuc2;
char harf;
while( adet <10 )
{
adet++;
printf("\nHarf giriniz : ") ; scanf(" %c", &harf ) ;
sonuc1= harfKontrol(harf) ;
if(sonuc1==1)
adet--;
sehpaCiz(adet);
if( sonucKontrol())
{
printf("\nTEBRIKLER KAZANDINIZ \n");
printf("\nBuldugunuz kelime : %s\n", kelime) ;
break;
}
}
return 0;
}
Hiç yorum yok:
Yorum Gönder
Her yorum bilgidir. Araştırmaya devam...