Untitled
unknown
plain_text
a year ago
5.1 kB
12
Indexable
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include<stdbool.h>
#include <ctype.h>
#include <time.h>
#include <windows.h>
#define maximum_try 10
int design_part(int x)
{
printf("\n");
printf("\n");
printf("\n");
printf(" -------+\n");
printf(" | | \n ");
printf(" | o \n ");
printf(" | / \\ \n");
printf(" | | \n");
printf(" | / \\ \n");
printf(" |\n\n");
for (int i = 1; i <= 25; i++)
{
Sleep(50);
printf("\r");
for (int j = 1; j <= i; j++)
{
printf(".");
}
}
printf("\n");
printf(" | H A N G M A N | \n");
printf("\n\n");
Sleep(500);
system("cls");
printf(" ..................................................\n");
printf(" | Hangman Rules |\n");
printf(" ..................................................\n");
printf(" | Maximum 10 mistakes are allowed. | \n");
printf(" | All alphabet are in lower case. |\n");
printf(" | All words are very popular Websites | \n");
printf(" | If you enjoy continue, otherwise close it |\n");
printf(" ..................................................\n");
printf("\n\n");
return 1;
}
int func_checking(const char *selectword, char guess, char *g_w)
{
bool flag=false;
for (int i = 0;selectword[i] != '\0';i++)
{
if(selectword[i] == guess)
{ g_w[i] = selectword[i]; flag = true; }
}
return flag;
}
int main()
{
design_part(1);
const char *Sports[] = {"golf","boxing","hockey","snake","xare"};
const char *Colors[] = {"red","blue","orange","black","white"};
const char *Food[] = {"quiche","burger","spagheti","yogurt","mango"};
printf(" Click ENTER to start the game : _");
printf("\n\n");
getchar();
system("cls");
printf("\n\n ----------------------------------\n");
printf(" | Please! Choose any option |\n");
printf(" ----------------------------------\n");
printf(" | 1.Sport |\n");
printf(" | 2.Color |\n");
printf(" | 3.Food |\n");
printf(" ---------------------------------\n");
int x;
for (;1;)
{
printf("Choice your option -> ");
scanf("%d", &x);
if (x >= 1 && x <= 4)
{
system("cls");
for (int i = 1; i <= 25; i++)
{
Sleep(50);printf("\r");
for (int j = 1; j <= i; j++)
{printf(".");}
}
system("cls");break;
}
else {printf("Invalid!!! Please type between 1 to 4\n");}
}
const char *g_word;
switch (x)
{
case 1:
srand(time(NULL));
g_word = Sports[rand() % 5];
break;
case 2:
srand(time(NULL));
g_word = Colors[rand() % 5];
break;
case 3:
srand(time(NULL));
g_word = Food[rand() % 5];
break;
default:
printf("Default case is Matched.");
break;
}
int s_word = strlen(g_word);
printf("SIZE OF WORD -> %d\n\n", s_word);
char g_w[20]={0},g_char[20]={0};
g_w[s_word] = '\0';
int w = 0,r = 0;
do{
printf("Enter a letter: ");
char guess;
scanf(" %c", &guess);
if (!strchr(g_char,tolower(guess)))
{
g_char[strlen(g_char)] = tolower(guess);
if (func_checking(g_word,tolower(guess),g_w))
{
r++;
printf("Correct guess!\n");
}
else
{
w++;
printf("Wrong guess! You have %d guesses left.\n", maximum_try - w);
}
printf("Guessed letters: %s\n", g_w);
}
else
{
printf("You already guessed that letter. Try again.\n");
}
}
while (r<s_word && w<10);
if (r == s_word)
{
printf("\nYAHOO!!!!! You are the WINNER\n");
printf("\n");
printf("\n");
printf(" -------+\n");
printf(" | | \n ");
printf(" | \\o/ \n");
printf(" | | \n");
printf(" | / \\ \n\n\n");
printf("The word is - > %s", g_word);
}
else
{
printf("\n The Word was -> %s ",g_word);
printf("\n The man is dead you IDIOT!!");
printf("\n Better luck next!!");
}
return 0;
}
Editor is loading...
Leave a Comment