#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
void drawMan(int life);
void game(void);
char *voca[] = {"accolade","adamant","admonition","affable","affinity","aftermath","ailing","aisles","amenable","amidst","among","apocryphal","appall","arousal","assuage","awash","bared","barely","bear","beef","beg","bend","bend","beneath","bequest","besiege","bet","bind","binge","blade","blasphemy","blast","blazing","blister","blow","blunt","boast","bobbing","bolster","bout","brag","brash","breed","brevity","bribe","brusque","burden","burglary","burst","cacophony","calf","callus","captivity","cartons","catering","cattle","cease","censure","chimera","chuckle","churning","claim","clam","clamor","clash","clemency","clever","clumsy","clutch","coalesce","cock","coeds","cognizant","come about","commiserate","complaisant","comprised","concealed","concern","contract","convey","convict","copious","copper","couch","crap","craze","crop","crotch","culprit","cumbersome","curl","dainty","dairy","dare","dart","dawn","dazzling","deaf","dean","dearth","decadence","decay","deceive","deed","defy","demise","denim","dentures","depleted","deputy","desultory","deter","devise","diatribe","dimple","dire","disgruntled","dispassionate","distress","donor","downwind","doze","draped","dreary","drizzling","drowziness","dull","dumb","duplicity","duty","dye","ease","edge","edifice","eerie","effervescent","eloquent","embrace","endowed","endure","enmity","equivocal","erroneous","exemplary","expedient","exuberance","fad","faint","fair","fancy","fast","feat","feather","fetter","fidget","fizz","flair","flare","flaw","fledgling","flood","flunk","folly","footstool","frantic","fright","fringe","frivolous","fulfill","garbled","garments","garner","gauntlet","gerbil","giggle","glazed","gloomy","gorgeous","grated","gravel","gravity","greedy","grief","grim","grip","groan","groovy","groping","ground","grudge","gut","hackneyed","haggle","hail","haphazard","harm","harsh","harvest","hassle","hasty","hatch","haunt","haze","heal","hedge","heel","heist","hen","herd","heretic","hermit","hindrance","hindsight","hobbling","hold dear","hollow","hue","hurtle","impart","incessant","incidental","incite","indefatigable","indelible","infraction","inmate","insolvent","intricate","irascible","irresolute","jargon","jeopardy","jiggle","keen","kindle","knack","knob","ladder","lagging","lame","lampoon","languish","lavish","lead","lean","lease","leather","leery","leniency","levity","likely","limb","limp","loaf","loony","loosely","loquacious","lousy","ludicrous","lump","lurches","maize","meander","mend","mere","messy","miff","mild","misanthrope","mischievous","misleading","mock","mold","mole","mood","morose","moss","muck","mug","mull","nave","neat","negligent","nonchalance","obey","obtuse","odorless","offspring","onset","opaque","opulence","orchard","outnumber","outward","overwhelming","parsimonious","partake","paucity","paw","peak","peel","peripheral","peruse","pinch","plea","pledge","poised","popsicle","porch","poultry","pouring","praise","prank","preach","prodigal","profane","progeny","progeny","proximity","prudish","puddle","puffy","pulled","pun","pursuit","put up with","quarrel","querulous","rage","rash","rave","rebuke","recapitulate","recluse","regret","rehearse","rekindle","relieve","rely","remain","renounce","repent","reproach","rescind","resemble","respite","retreat","ribbing","riddle","ridge","rinds","ripe","roaring","roll out","rot","rough","rouse","rug","ruminate","ruse","rust","sagacious","sage","sate","savants","scrawl","screech","screw","scrutinize","seal","seam","seizing","sentient","settle","sew","shackle","shed","shelter","shingles","shiv","shoplift","shore","shriking","shrink","silk","silly","skewer","slash","slaughter","slight","slippers","slope","slug","slum","slump","sly","smear","snail","snap","snore","snub","soaked","sober","somber","soothed","sovereignty","sparkle","spotter","spouting","spree","spurious","squalid","squeeze","squirm","stage","stagnant","stale","stare","stark","steady","steep","stem cell","stickler","sticky","stiff","stingy","stir","stoic","stony","stooped","strain","stretch","stride","stripes","stroll","struck","stubborn","stun","stunt","substantiate","sulky","supplant","surreptitious","swallow","swamp","swath","sway","sweepings","thick","thigh","thorn","thrifty","tickle","tide","torpor","touchy","trite","trousers","trustee","trustworthy","tuckered","turd","udder","unassailable","uncanny","undergo","underneath","uniform","unobstrusive","unpleasant","unscathed","untenable","upbeat","upsetting","vacillate","vanish","veal","vex","vilify","vogue","voluminous","voracious","waist","wart","wax","weave","wedge","weeds","weird","welfare","whalebone","whinning","whipping","wholly","widen","wilted","wipe","wisdom","wise","wool","wool","worthy","wreck","wriggle","writhe"};
// 506 words
int main(void){
srand(time(NULL));
game();
return 0;
}
void game(void){
// Insert source code for Hangman game...
char *a=voca[rand()%506], alph[100],answer[100]="";
int len = 0,i = 0,j=0,m=0, n=0, life=7,e=1;
len = (strlen(a));
// scanf("%s",alph);printf("%c",alph[0]);
printf("Guess the word: ");
for(i=0 ;i < len ; i++)
printf("_ ");//맨 처음 시작. 모조리 빈칸
printf("\n");
printf("%s,%d,%c",a,len, a[0]);
while(life>0 || life==0){
scanf("%s ",alph);
if(life>0){
if(strlen(alph)==1){
if((alph[0]>('A'-1)) || (alph[0]<('Z'+1)))
alph[0]=(alph[0]-'A'+'a');
else if((alph[0]>('a'-1)) || (alph[0]<('z'+1)))
alph[0]=alph[0];
printf("Guess the word: ");
for(j=0;j<len;j++){
if( a[j]!=alph[0]){
answer[j]='_';
e++;
}
else if(a[j]==alph[0])
answer[j]=alph[0];
if(e==len) {
life--;
drawMan(life);
}
}
printf("%s",answer);
}
else if( strlen(alph)==len){
for(m=0;m<len;m++){
if((alph[m]>('A'-1)) || (alph[m]<('Z'+1)))
alph[m]=(alph[m]-'A'+'a'+1);
else if((alph[m]>('a'-1)) || (alph[m]<('z'+1)))
alph[m]=alph[m];
}//한글자이상의 배열을 다 소문자로 바꾸기
if(alph==a){
printf("Congratulations! You guesses my word! ");
break;
}
else{
life--;
drawMan(life);
}
}
else{
life--;//alph 길이가 1개 아니거나 정답이랑 다르면 쓸모가 없지
drawMan(life);
}
}
else if(life==0){
printf("Game over! The word was %s",a);//life가 0이 되면 끝나는거지
break;
}
}
}//반환값이 없지
void drawMan(int life){
switch(life){
case 0:
printf(" O\n/|\\\n |\n/\\\n");
break;
case 1:
printf(" O\n/|\\\n |\n/\n");
break;
case 2:
printf(" O\n/|\\\n |\n");
break;
case 3:
printf(" O\n/|\\\n");
break;
case 4:
printf(" O\n/|\n");
break;
case 5:
printf(" O\n |\n");
break;
case 6:
printf(" O\n");
break;
case 7:
printf("\n");
break;
}
}
1.alph를 한글자로 입력받는경우에는 대문자로 입력시에만 프로그램이 돌아가는데 소문자는 왜 안들어가는 걸까요?
2. alph가 정답 a와 같으면 congratulation이 나와야 하는데 왜 틀린걸로 인식할까요?ㅠ
3. alph를 입력받으면 _ 대신에 그 문자가 들어가야 하는데, 들어가긴 들어가는데 그 다음번 alph를 새로 받을때에 그 전 문자도 같이 입력된 상태를 어떻게 유지하나요? |