/*
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("Hello world!\n");
return 0;
}
*/
/*
#include<stdio.h>
#include<string.h>
#include<windows.h>
#include<math.h>
#include<time.h>
#define LEFT 75
#define RIGHT 77
#define UP 72
#define DOWN 80
void gotoxy(int x,int y)
{
COORD pos= {x,y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}
void setcolor(int x)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),x);
}
int map[25][25]={0};
int dx,dy;
int px,py;
int fx,fy;
int main()
{
char input;
srand(time(NULL));
setcolor(7);
dx=1;
dy=0;
px=5;
py=5;
fx=rand()%20+2;
fy=rand()%20+2;
map[fx][fy]=1;
gotoxy(fx,fy);
printf("@");
if(map[px][py]==map[fx][fy])
{
c++;
}
for(;;)
{
if(kbhit())
{
input=getch();
switch(input)
{
case DOWN:
dy=-1;
dx=0;
break;
case UP:
dy=-1;
dx=0;
break;
}
}
Sleep(100);
gotoxy(px,py);
printf(" ");
px+=dx;
py+=dy;
gotoxy(px,py);
printf("-");
}
}
*/
#include<stdio.h>
#include<string.h>
#include<windows.h>
#include<math.h>
#include<time.h>
void gotoxy(int x,int y)
{
COORD pos= {x,y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}
int main()
{
char input,p, words[5][10] = {"hello", "pineapple", "mango", "banana", "melon"};
char answer[10] = {0};
srand(time(NULL));
int randomNumber;
int c=20,k,i;
srand(time(NULL));
gotoxy(55,1);
printf("=======");
gotoxy(55,2);
printf("HANGMAN");
gotoxy(55,3);
printf("=======");
gotoxy(50,10);
printf("PRESS 'E' to START");
for(;;)
{
if(kbhit())
{
input = getch();
if(input=='E'||input=='e')
{
system("cls");
gotoxy(55,13);
printf("START!");
Sleep(1000);
system("cls");
break;
}
}
}
gotoxy(50,13);
printf("알파벳을 입력해주세요");
randomNumber = rand()%strlen(words);
for(;;)
{
system("cls");
for(i=0; i<strlen(words[randomNumber]); i++)
{
gotoxy(50,1);
printf("기회:%d",c);
gotoxy(50+i,14);
if(answer[i]==0)
{
printf("_");
}
else
{
printf("%c", words[randomNumber][i]);
}
}
gotoxy(50, 15);
scanf(" %c", &p);
for(i=0; i<strlen(words[randomNumber]); i++)
{
if(p==words[randomNumber][i])
{
answer[i] = 1;
}
else
{
c--;
gotoxy(50,1);
printf("기회:%d",c);
}
if(c==0)
{
system("cls");
gotoxy(50,13);
printf("Game over");
}
}
}
}