Hangman is a paper and pencil guessing game for two or more players. One player thinks of a word and the other tries to guess it by suggesting letters.
_______
|/ |
| O
| \|/
| |
| / \
__|_________
The word to guess is represented by a row of dashes, giving the number of letters. If the guessing player suggests a letter which occurs in the word, the other player writes it in all its correct positions. If the suggested letter does not occur in the word, the other player draws one element of the hangman diagram as a tally mark. The game is over when:
An example game in progress; the answer is Wikipedia.
* The guessing player completes the word, or guesses the whole word correctly
* The other player completes the diagram:
This diagram is, in fact, designed to look like a hanging man. Although debates have arisen about the questionable taste of this picture, it is still in use today. A common alternative for teachers is to draw an apple tree with ten apples, erasing or crossing out the apples as the guesses are used up.
The exact nature of the diagram differs; some players draw the gallows before play and draw parts of the man's body (traditionally the head, then the torso, then the left arm, then the right arm, then the left leg, then the right leg). Some players begin with no diagram at all, and drawing the individual elements of the gallows as part of the game, effectively giving the guessing players more chances. The amount of detail on the man can also vary, affecting the number of chances. Many players include a face on the head, either all at once or one feature at a time.
Some modifications to game play, such as "buying a vowel", result from the U.S. television game show Wheel of Fortune, created by Merv Griffin.
My -- Hangman C programming code
------------------------------------------------
#include
#include
#define len 8
int try1(){
printf("---------------\n");
printf("failed \n");
printf("---------------\n");
}
int try2(){
static int i=9;
static int j=0;
i--;
printf("\t %d more chances \n",i);
j++;
prn_galg(j);
while( i == 0){
printf("Time out \n");
exit(-1);
}
}
int showlogo() {
printf("--------------------------------------------\n");
printf("| # # # # # #### # # # # # |\n");
printf("| # # # # ## # # ## ## # # ## # |\n");
printf("| #### ##### # # # # ## # # # ##### # # # |\n");
printf("| # # # # # ## # # # # # # # ## |\n");
printf("| # # # # # # ### # # # # # # |\n");
printf("--------------------------------------------\n\n");
}
void prn_galg(int i) {
switch (i) {
case 0 :
// printf("Amount of wrong letters: %d\n\n", i);
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("____________\n\n");
break;
case 1 :
// printf("Amount of wrong letters: %d\n\n", i);
printf("\n");
printf(" |\n");
printf(" |\n");
printf(" |\n");
printf(" |\n");
printf(" |\n");
printf("__|_________\n\n");
break;
case 2 :
// printf("Amount of wrong letters: %d\n\n", i);
printf(" _______\n");
printf(" |\n");
printf(" |\n");
printf(" |\n");
printf(" |\n");
printf(" |\n");
printf("__|_________\n\n");
break;
case 3 :
// printf("Amount of wrong letters: %d\n\n", i);
printf(" _______\n");
printf(" |/\n");
printf(" |\n");
printf(" |\n");
printf(" |\n");
printf(" |\n");
printf("__|_________\n\n");
break;
case 4 :
// printf("Amount of wrong letters: %d\n\n", i);
printf(" _______\n");
printf(" |/ | \n");
printf(" | O \n");
printf(" |\n");
printf(" |\n");
printf(" |\n");
printf("__|_________\n\n");
break;
case 5 :
// printf("Amount of wrong letters: %d\n\n", i);
printf(" _______\n");
printf(" |/ | \n");
printf(" | O \n");
printf(" | |\n");
printf(" | |\n");
printf(" |\n");
printf("__|_________\n\n");
break;
case 6 :
// printf("Amount of wrong letters: %d\n\n", i);
printf(" _______\n");
printf(" |/ | \n");
printf(" | O \n");
printf(" | \\|\n");
printf(" | | \n");
printf(" |\n");
printf("__|_________\n\n");
break;
case 7 :
// printf("Amount of wrong letters: %d\n\n", i);
printf(" _______\n");
printf(" |/ | \n");
printf(" | O \n");
printf(" | \\|/\n");
printf(" | | \n");
printf(" |\n");
printf("__|_________\n\n");
break;
case 8 :
// printf("Amount of wrong letters: %d\n\n", i);
printf(" _______\n");
printf(" |/ | \n");
printf(" | O \n");
printf(" | \\|/\n");
printf(" | | \n");
printf(" | /\n");
printf("__|_________\n\n");
break;
case 9 :
// printf("Amount of wrong letters: %d\n\n", i);
printf(" _______\n");
printf(" |/ | \n");
printf(" | O \n");
printf(" | \\|/\n");
printf(" | | \n");
printf(" | / \\\n");
printf("__|_________\n\n");
break;
case 10 :
// printf("Amount of wrong letters: %d\n\n", i);
printf(" _______\n");
printf(" |/ | \n");
printf(" | X \n");
printf(" | \\|/\n");
printf(" | | \n");
printf(" | / \\\n");
printf("__|_________\n\n");
break;
}
}
int main(){
/* here in "hangman" to be found is "h _ _ g _ _ n" */
char h[len] = "hangman";
char c[len];
stop :
showlogo();
printf("**Welcome to Hangman Code**\n");
printf("word to find is h _ _ g _ _ n\n");
// printf(" Find H 1 2 G 3 4 N \n");
printf("Press 'e' for quit \n");
printf("Try for the 1 letter: \n");
c[0] = getchar();
if(c[0]== 'e'){
exit(-1);
}
try2();
while(c[0] == h[1]){ // A
c[1] = getchar();
while (c[1] == h[2]){ // N
c[2] = getchar();
while (c[2] == h[4]){ // M
c[3] = getchar();
while (c[3] == h[5]){ //N
printf("Hurray you have completed \n");
printf("****************************************\n");
printf("****************************************\n");
printf("Completed letters are %c%c%c%c%c%c%c \n",h[0],h[1],h[2],h[3],h[4],h[5],h[6]);
printf("****************************************\n");
printf("****************************************\n");
printf("Success you have made the Hangman code \n");
goto stop;
}
try2();
printf("Completed letters are %c%c%c%c%c _ n \n",h[0],h[1],h[2],h[3],h[4]);
printf("Try for the 4 letter: \n");
}
try2();
printf("Completed letters are %c%c%cg _ _ n \n",h[0],h[1],h[2]);
printf("Try for the 3 letter: \n");
}
try2();
printf("Completed letters are %c%c _ g _ _ n \n",h[0],h[1]);
printf("Try for the 2 letter :\n");
}
{
goto stop;
}
return 0;
}
// this is a sample base code i have written . Still more efficient code will be released // as soon as possible.
Thanks to
wikipedia
http://en.wikipedia.org/wiki/Hangman_(game)
www.daniweb.com/code/post1157561.html
No comments:
Post a Comment