Kollywood Game

A simple game which we have all played once in their life,Actually according to the program the user has to give the movie name and then he has to find it which sounds silly. i could not come up with any better solution for this , so if you have any better solution please do comment . works better with two players .one has to provide the movie name as input and the other can find the movie name.

code:

#include<stdio.h>
#include<string.h>
#include<conio.h>
int checkflag(int size,char str[size])
{
    for(int i=0;str[i]!='\0';i++)
    {
        if(str[i]=='_')
        {
            return 1;
        }
    }
    return 0;
}
int checkkolly(int size,char str[size])
{
    for(int i=0;str[i]!='\0';i++)
    {
        if(str[i]!='*')
        {
            return 1;
        }
    }
    return 0;
}
int main()
{
    char movie_name[100];
    printf("\n Enter the movie name(player 1)\n");
    scanf(" %[^\n]s",movie_name);
    clrscr();
    char str[10]="kollywood";
    int len=strlen(movie_name);
    char display[len+1];
    int i;
    int j=0;
    for(i=0;i<len;i++)
    {
        display[i]='_';
    }
    display[i]='\0';
    printf("Player 2\n ");
    while(1)
    {
        char str2[2];
        printf("\n Enter the letter \n");
        scanf("%s",str2);
        char temp=str2[0];
        int flag=0;
        for(i=0;movie_name[i]!='\0';i++)
        {
            if(movie_name[i]==temp)
            {
                display[i]=temp;
                flag=1;
            }
        }
        if(flag!=1)
        {
            str[j]='*';
            if(checkkolly(10,str)==0)
            {
            clrscr();
            printf("You lose!!");
            break;
            }
            j++;
        }
        printf("%s \t |\t %s \n\n\n",display,str);
        if(checkflag(len,display)==0)
        {
            clrscr();
            printf("You won!!");
            break;
        }
    }
}

output:

                                                                                                                                               
Enter the movie name(player 1)                                                                                                                  
theamazingspiderman                                                                                                                            
                                                                  
Player 2                                                                                                                                         
                                                                                                                                                 
 Enter the letter                                                                                                                                
t                                                                                                                                                
t__________________      |       kollywood                                                                                                       
                                                                                                                                                 
                                                                                                                                                 
                                                                                                                                                 
 Enter the letter                                                                                                                                
a                                                                                                                                                
t__a_a___________a_      |       kollywood                                                                                                       
                                                                                                                                                 
                                                                                                                                                 
                                                                                                                                                 
 Enter the letter                                                                                                                                
i                                                                                                                                                
t__a_a_i____i____a_      |       kollywood                                                                                                       
                                                                                                                                                 
                                                                                                                                                 
                                                                                                                                                 
 Enter the letter                                                                                                                                
e                                                                                                                                                
t_ea_a_i____i_e__a_      |       kollywood                                                                                                       
                                                                                                                                                 
                                                                                                                                                 
                                                                                                                                                 
 Enter the letter                                                                                                                                
o                                                                                                                                                
t_ea_a_i____i_e__a_      |       *ollywood

                                                                                                                                                
                                                                                                                                                 
                                                                                                                                                 
 Enter the letter                                                                                                                                
u                                                                                                                                                
t_ea_a_i____i_e__a_      |       **llywood                                                                                                       
                                                                                                                                                 
                                                                                                                                                 
                                                                                                                                                 
 Enter the letter                                                                                                                                
n                                                                                                                                                
t_ea_a_in___i_e__an      |       **llywood                                                                                                       
                                                                                                                                                 
                                                                                                                                                 
                                                                                                                                                 
 Enter the letter                                                                                                                                
m                                                                                                                                                
t_eama_in___i_e_man      |       **llywood                                                                                                       
                                                                                                                                                 
                                                                                                                                                 
                                                                                                                                                 
 Enter the letter                                                                                                                                
r                                                                                                                                                
t_eama_in___i_erman      |       **llywood                                                                                                       
                                                                                                                                                 
                                                                                                                                                 
                                                                                                                                                 
 Enter the letter                                                                                                                                
k                                                                                                                                                
t_eama_in___i_erman      |       ***lywood                                                                                                       
                                                                                                                                                 
                                                                                                                                                 
                                                                                                                                                 
 Enter the letter                                                                                                                                
l                                                                                                                                                
t_eama_in___i_erman      |       ****ywood                                                                                                       
                                                                                                                                                 
                                                                                                                                                 
                                                                                                                                                 
 Enter the letter                                                                                                                                
h                                                                                                                                                
theama_in___i_erman      |       ****ywood                                                                                                       
                                                                                                                                                 
                                                                                                                                                 
                                                                                                                                                 
 Enter the letter                                                                                                                                
g                                                                                                                                                
theama_ing__i_erman      |       ****ywood                                                                                                       
                                                                                                                                                 
                                                                                                                                                 
                                                                                                                                                 
 Enter the letter                                                                                                                                
s                                                                                                                                                
theama_ings_i_erman      |       ****ywood 
                                                                                                                                                
                                                                                                                                                 
 Enter the letter                                                                                                                                
p                                                                                                                                                
theama_ingspi_erman      |       ****ywood                                                                                                       
                                                                                                                                                 
                                                                                                                                                 
                                                                                                                                                 
 Enter the letter                                                                                                                                
d                                                                                                                                                
theama_ingspiderman      |       ****ywood                                                                                                       
                                                                                                                                                 
                                                                                                                                                 
                                                                                                                                                
 Enter the letter                 
p

theamazingspiderman


youwon!!                                                                   
                        


Comments

  1. Hey bro :)
    Cool program
    Hoping for more awesome code from you

    ReplyDelete
  2. Kollywood nu sollidu.. amazingspiderman nu padam kudukura

    ReplyDelete

Post a Comment

Popular posts from this blog

c++ program to print string along the diagonals of the matrix.

C program to print the following Pattern