1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
|
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <conio.h>
void randomiz(char*);
void Guess(char*,int*,int*);
void main()
{
char *word= {"random"};
long int x;
int b, score=0,ctr2=0;
time_t t;
clrscr();
srand((unsigned)time(&t));
randomiz(word);
score = ctr2 = 0;
Guess(word,&score,&ctr2);
gotoxy(10,11);
printf("You got a %d", score);
getch();
}
void randomiz(char* y)
{
char A[256] = {'\0'};
int i=0, x, k, j, z;
int n[256]= {'\0'};
time_t t;
x = strlen(y);
srand((unsigned)time(&t));
clrscr();
printf("\n\n\n\t\t\t\t");
while (i<x)
{
a:;
j = rand()%x;
z = 0;
for (k=0,z=0; k<i; k++)
if (n[k]==j)
z++;
if (z!=0)
goto a;
else
{
n[i] = j;
A[i] = y[j];
gotoxy(27,30);
printf(" %c ", A[i]);
i++;
}
}
return;
}
void Guess(char* word,int* score,int* ctr2)
{
int ctr;
FILE* fp;
char guess[256] = {'\0'};
ctr = *score;
while(1){
q:
gotoxy(10,10);
printf(">> ");
gets(guess);
if (strcmp(guess,"-exit")==0)
exit(1);
if (strcmp(guess,"1")==0)
{
randomiz(word);
goto q;
}
else
fp = fopen("wlist1.txt", "r");
while (!feof(fp))
{
fscanf(fp, "%s\n", word);
if (stricmp( word, guess)==0)
{
*score += strlen(guess)*10;
gotoxy(55,2);
printf("score: %d", strlen(guess)*10);
fclose(fp);
goto q;
}
}
fclose(fp);
if (*score==ctr)
{
gotoxy(10,12);
printf("Oops Sorry!!");
getch();
goto q;
}
else if(*score>ctr && *score<100)
{
gotoxy(10,13);
printf("Correct!!");
getch();
goto q;
}
else
{
gotoxy(45,30);
printf("You Won!");
return;
}
}
}
|