Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //This program features:
- // 1) A sound effect when the player guess a right or wrong letter
- // 2) In this game program, the player has 6 chances to guess wrong
- // 3) There is an option to replay the game when the game ends
- // 4a) During the game, the game features green colour when lives is more than half
- // 4b) During the game, the game features yellow colour when lives is half
- // 4c) During the game, the game features red colour when lives is less than half
- // 5) In this game program, the player can choose to enter their own word or get a random word
- #include <stdio.h>
- #include <stdlib.h>
- #include <conio.h>
- #include <string.h>
- // function prototypes
- void intro();
- void displayscreen();
- void answer();
- void hangman();
- int key;
- void main()
- {
- intro();
- answer();
- }
- void intro()
- {
- system("COLOR B");
- printf("\t\t\t\t\t Welcome to...\n\n");
- Sleep(1000);
- printf("\t\t\t## ## ###### ## ## ###### ## ## ###### ## ##\n");
- printf("\t\t\t## ## ## ## ### ## ## ## ### ### ## ## ### ##\n");
- printf("\t\t\t###### ## ## ## # ## ## ## # ## ## ## ## # ##\n");
- printf("\t\t\t###### ###### ## # ## ## ### ## # ## ###### ## # ##\n");
- printf("\t\t\t## ## ## ## ## ### ## ## ## ## ## ## ## ###\n");
- printf("\t\t\t## ## ## ## ## ## ###### ## ## ## ## ## ##\n");
- Sleep(1000);
- printf("\n\n\t\t\t\tIF YOU GUESS WRONG TOO MANY TIMES");
- Sleep(1000);
- system("COLOR 4");
- printf("\n\n\n\t\t\t\t\tYOU WILL BE HANGED");
- Sleep(1000);
- printf("\n\n\n\t\t\t\t\t Good Luck!");
- Sleep(1500);
- printf("\n\n\n\n\n\nGame Instruction");
- printf("\n****************");
- printf("\nYou are given 6 attempts for your mistake guessing.\n");
- getche();
- }
- void displayscreen()
- {
- printf("\n\t********************\n");
- printf("\t* *\n");
- printf("\t* Hangman *\n");
- printf("\t* *\n");
- printf("\t********************\n");
- }
- void answer()
- {
- char guessed[30];
- char Word[2][20];
- char letter,pick;
- int i,attempt=0,n=0;
- strcpy(Word[1],"apple orange");
- strcpy(Word[2],"samsung");
- srand(Word);
- pick = rand()%2;
- system("COLOR F");
- for (i=0;i<strlen(Word);i++)
- {
- guessed[i]='_';
- if(Word[pick][i]==' ')
- {
- guessed[i]=' ';
- }
- }
- while (attempt<=6||strcmp(Word,guessed)==0)
- {
- system("cls");
- displayscreen();
- {
- printf("\n\tGuessing Word:");
- }
- for(i=0;i<strlen(Word);i++)
- {
- printf(" %c ",guessed[i]);
- }
- if (strcmp(Word,guessed)==0)
- {
- printf("\n\tYou Have Guessed The Correct Word!");
- system("mario_win.wav");
- }
- else if (attempt==6)
- {
- printf("\n\tYou Lose!");
- system("mario_lose.wav");
- }
- hangman(attempt);
- letter=getche();
- for (i=0; i<strlen(Word);i++)
- {
- if (Word[i]==letter)
- {
- guessed[i]=letter;
- }
- else
- {
- attempt++;
- }
- }
- if (attempt==6||strcmp(Word,guessed)==0)
- {
- break;
- }
- }
- puts("\nPress any key to start, 'q' - to quit");
- key=getch();
- while (key!= 113 )
- {
- return answer;
- }
- }
- void hangman(int attempt)
- {
- puts("\n");
- puts("\t ############");
- puts("\t ### ##");
- puts("\t ### ##");
- if (attempt<=0)
- {
- puts("\t ###");
- puts("\t ###");
- puts("\t ###");
- puts("\t ###");
- }
- else
- {
- printf("\t ###");
- //system("COLOR 5");
- puts(" +-----+");
- //system("COLOR 1");
- printf("\t ###");
- //system("COLOR 5");
- puts(" | |");
- //system("COLOR 1");
- printf("\t ###");
- //system("COLOR 5");
- puts(" | |");
- //system("COLOR 1");
- printf("\t ###");
- //system("COLOR 5");
- puts(" +-----+");
- //system("COLOR 1");
- }
- if (attempt==2)
- {
- printf("\t ###");
- //system("COLOR 5");
- puts(" ||");
- //system("COLOR 1");
- printf("\t ###");
- //system("COLOR 5");
- puts(" ||");
- //system("COLOR 1");
- printf("\t ###");
- //system("COLOR 5");
- puts(" ||");
- //system("COLOR 1");
- }
- else if (attempt==3)
- {
- printf("\t ###");
- //system("COLOR 5");
- puts(" ||");
- //system("COLOR 1");
- printf("\t ###");
- //system("COLOR 5");
- puts(" ====||");
- //system("COLOR 1");
- printf("\t ###");
- //system("COLOR 5");
- puts(" ||");
- //system("COLOR 1");
- }
- else if ( attempt <= 3 )
- {
- puts("\t ###");
- puts("\t ###");
- puts("\t ###");
- }
- else
- {
- printf("\t ###");
- //system("COLOR 5");
- puts(" ||\t");
- //system("COLOR 1");
- printf("\t ###");
- //system("COLOR 5");
- puts(" ====||====");
- //system("COLOR 1");
- printf("\t ###");
- //system("COLOR 5");
- puts(" ||\t");
- //system("COLOR 1");
- }
- if (attempt==5)
- {
- printf("\t ###");
- //system("COLOR 5");
- puts(" //");
- //system("COLOR 1");
- printf("\t ###");
- //system("COLOR 5");
- puts(" // ");
- //system("COLOR 1");
- }
- else if (attempt<=5)
- {
- puts("\t ###");
- puts("\t ###");
- }
- else
- {
- printf("\t ###");
- //system("COLOR 5");
- puts(" //\\\\ ");
- //system("COLOR 1");
- printf("\t ###");
- //system("COLOR 5");
- puts(" // \\\\");
- //system("COLOR 1");
- }
- puts("\t ###");
- puts("\t#######");
- puts("\t#######");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement