프로필

가입일: 2020년 9월 24일

소개
0 좋아요
0 개 댓글
0 베스트 답변


#include <stdio.h>//standard input output .. printf, scanf

#include <windows.h>

#include <stdlib.h> //srand, rand를 사용하기 위한 헤더파일

#include <time.h> // time을 사용하기 위한 헤더파일

void gotoxy(int x, int y)

{

COORD pos= {x,y};

SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);

}


void gamestart()

{


gotoxy(40,10);

Sleep(300); printf("G");

Sleep(300); printf("A");

Sleep(300); printf("M");

Sleep(300); printf("E");

Sleep(300); printf(" ");

Sleep(300); printf("S");

Sleep(300); printf("T");

Sleep(300); printf("A");

Sleep(300); printf("R");

Sleep(300); printf("T");

Sleep(300); printf("!");

Sleep(300); printf("!");

Sleep(300); printf("!");

Sleep(300); //1000 1초

system("cls");

}

void printlife(int k)

{

int i;

gotoxy(80,17);

for(i=1; i<=k; i++)

{

printf("★");

}

for(i=1; i<=5-k; i++)

{

printf("☆");

}

}



int main()

{


int b=1;

char z[50]= {0};

char answerlist[3][50][50]= {{"apple","banana","watermelon","orange","grapes"},

{"chrome","google","naver","yotube","games"},{"computer","phone","television","ipad","air conditioner"}

};

char answer[50];

char answerb[50];

char ch;

int i;

int k=3;

gamestart();

while(1)

{

gotoxy(10,5); //종류 메뉴 위치 정하기

printf("1.fruits\n 2.web\n 3.machine\n");

char kinds[30]= {};

gotoxy(50,7);

scanf("%s",kinds);

int ks;

if(strcmp(kinds,"1")==0)

{

ks=0;

gotoxy(25,1);

printf("1.fruits");

}

else if(strcmp(kinds,"2")==0)

{

ks=1;

gotoxy(25,1);

printf("2.web");

}

else

{

ks=2;

gotoxy(25,1);

printf("3.machine");

}


system("cls");

Sleep(300);

gotoxy(1,1);

printf("%d 번째 게임", b);

k=5;

if(strcmp(kinds,"1")==0)

{

gotoxy(88,2);

printf("1.fruits");

}

else if(strcmp(kinds,"2")==0)

{

gotoxy(88,2);

printf("2.web");

}

else

{

gotoxy(88,2);

printf("3.machine");

}

srand(time(NULL));

int random = rand() % 5; // 0 ~ 4

strcpy(answer,answerlist[ks][random]); //랜덤 답 뽑기

for(i=0; i<50 ; i++)

answerb[i]=0; //답지판 초기화

for(i=0; i<strlen(answer) ; i++)

answerb[i]='_';

while(1)

{

printlife(k);

gotoxy(40,3);

printf("문자를 입력하세요 : ");

scanf(" %c",&ch);

int flag = 0;

for(i=0; i<strlen(answer) ; i++)

{

if(ch == answer[i])

{

flag=1; answerb[i]=answer[i];

}

}

if(flag==1)

{

gotoxy(48,5);

printf("%s\n",answerb); //정답 출력

if(strcmp(answer,answerb)==0)

{

system("cls"); //화면 전체 지우기

gotoxy(43,3);

printf("You Win !!!\n");

gotoxy(42,8);

printf("게임 다시하기");

gotoxy(45, 12);

printf("yes no");

gotoxy(47,14);

scanf("%s", z);

b++;

if(strcmp(z,"no")==0)

return 0;

else

{

system("cls");

break;

}

}

}

else if(flag==0)

{

if(k==1)

{

system("cls"); //콘솔 전체 지우기

gotoxy(44,3);

printf("GAME OVER\n\n\n\n\n");

gotoxy(42,8);

printf("게임 다시하기");

gotoxy(45, 12);

printf("yes no");

gotoxy(48,14);

scanf("%s", z);

b++;

if(strcmp(z,"no")==0)

return 0;

else

{

system("cls");

break;

}

}

else

k--;

}

}

}

return 0;


}

pjy0809

더보기