#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<windows.h>
#include<time.h>
#include<string.h>
#define MAXSIZE 10
#define _CRT_OBSOLETE_NO_WARNINGS
char word[MAXSIZE][20] = {"orange", "apple", "mandarin", "watermelon", "mango", "grape", "melon", "strawberry", "banana", "fineapple"};
char answer[20] = { 0,};
void gotoxy(int x,int y)
{
COORD pos= {x,y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}
int main()
{
FILE *fp;
int x, y, z, count,score=0,left=10;
char a, b, c, hp;
int rTotal, rWin, rLose;
fp = fopen("data.txt", "r+");
fscanf(fp, "%d %d %d", &rTotal, &rWin, &rLose);
fclose(fp);
printf("%d %d %d", rTotal, rWin, rLose);
scanf("%d", &x);
rTotal++, rWin++, rLose++;
fp = fopen("data.txt", "w");
fprintf(fp, "%d %d %d", rTotal, rWin, rLose);
fclose(fp);
srand(time(NULL));
gotoxy(1,0);
//system("cls");
x = rand()%10;
gotoxy(20,0);
printf("_----------------문제 현황판---------------_");
gotoxy(10, 0);
printf("\n틀린 횟수: %d",count);
int len_answer =strlen(word[x]);
gotoxy(32, 5);
printf("남은 목숨: %d ",left);
gotoxy(30, 3);
printf("숨겨진 단어:");
for(int i=0; i<len_answer; i++)
{
answer[i]='_';
gotoxy(44+i, 3);
printf("%c",answer[i]);
}
for(;;)
{
gotoxy(24, 7);
printf("답을 입력하십시오:");
scanf(" %c ", &b);
int right=0;
for(int i=0; i<=len_answer; i++)
{
if(word[x][i]==b)
{
answer[i]=word[x][i];
right=1;
}
}
if(right==0)
{
count++;
gotoxy(10, 0);
printf("\n틀린 횟수: %d",count);
left--;
gotoxy(32, 5);
printf("남은 목숨: %d ",left);
}
for(int i=0; i<len_answer; i++)
{
gotoxy(44+i, 3);
printf("%c",answer[i]);
}
printf("\n");
_sleep(1000);
if(strcmp(answer, word[x]) == 0)
{
system("cls");
gotoxy(20,4);
printf("축하합니다! 성공하셨어요!");
_sleep(1000);
gotoxy(20,5);
printf("정답 현황");
_sleep(1000);
gotoxy(20,7);
printf("문제 단어: %s ",word[x]);
_sleep(1000);
gotoxy(20,9);
printf("틀린 횟수: %d ",count);
_sleep(1000);
gotoxy(20,11);
printf("남은 목숨: %d ",left);
_sleep(5000);
system("cls");
gotoxy(20,13);
printf("done!");
break;
}
if(count == 10)
{
system("cls");
gotoxy(20,5);
printf("%d번을 실패하셨고, 성공하시지 못하였습니다.\n",count);
gotoxy(20,7);
printf("정답: %s",word[x]);
break;
}
}
return 0;
}