Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Game Programming (http://www.go4expert.com/articles/game-programming/)
-   -   Hangman game source code (http://www.go4expert.com/articles/hangman-game-source-code-t1142/)

TEJUS 9Aug2006 13:52

Hangman game source code
 
Hangman game source code for you.
============
----HANGMAN----
============
Code: C

#include<conio.h>
#include<string.h>
main()
{
    char word[30],getit[30],*found;
    int score,loop,len,num,lup,om,luptimes,times,fitimes,ondtimes,antimes;
    luptimes=0;
    fitimes=0;
    ondtimes=0;
    clrscr();
    printf("\n ENTER THE WORD: ");
    gets(word);
    score=0;
    num=0;
    om=0;
   
    len=strlen(word);
    clrscr();
    char gname[70];
    printf("\n ENTER YOUR NAME: ");
    scanf("%s",gname);
    char h;
    printf("\n LET's START: ");
    h='_';
    printf("\n LOOK HERE: ");
    for(loop=0;loop!=len;loop++)
    {
        printf("\n %c ",h);
    }
    for(loop=0;loop!=len;loop++)
    {
        om=1;
        num=num+1;
        fitimes=0;
        ondtimes=0;
        printf("\n\n %d LETTER",num);
        scanf("%s",&getit[num]);
        found=strchr(word,getit[num]);
        if(found)
        {
            for(luptimes=0;antimes=1;luptimes!=len;luptimes++,antimes++)
            {
                if(getit[num]==word[luptimes])
                {
                    fitimes++;
                }
                else
                {
                    fitimes=fitimes;
                }
            }
            for(luptimes=num;luptimes!=0;luptimes--)
            {
                if(getit[num]==getit[luptimes])
                {
                    ondtimes++;
                }
                else
                {
                    ondtimes=ondtimes;
                }
            }
            if(fitimes>=ondtimes)
            {
                score=score+1;
                printf("\n OK\n");
                for(lup=0;getit[num]!=word[lup];lup++)
                {
                    om++;
                }
                printf("\n POSITION: %d\n",om);
                printf("\n ===================\n");
            }
            else
            {
                score=score;
                printf("\n NOT AGAIN!\n");
            }
        }
        else
        {
            score=score;
            printf("\n NO\n");
        }
    }
    printf("\n THE WORD IS '%s'\n"word);
    printf("\n YOUR SCORE IS %d OUT OF %d",score,len);
    getch();
    return 0;
}


TEJUS 3Nov2006 19:10

Re: Hangman game source code
 
Why No One Is Replying ?

shabbir 3Nov2006 19:22

Re: Hangman game source code
 
What you want in reply?

TEJUS 25Nov2006 11:53

Re: Hangman game source code
 
i want to know wheter my program is good?

shabbir 25Nov2006 14:39

Re: Hangman game source code
 
Quote:

Originally Posted by TEJUS
i want to know wheter my program is good?

Yup its a good one I must say.

Not more people are replying or commenting probably because of lack of some explanation / introductory para.

shailender0435 1Dec2006 23:21

Re: Hangman game source code
 
hey iam getting an error
undefined symbol_main in module c).ASM

rai_gandalf 4Dec2006 00:24

9 Errors and 5 Warnings!! Whats this?!
 
Quote:

Originally Posted by shabbir
Yup its a good one I must say.

Not more people are replying or commenting probably because of lack of some explanation / introductory para.


How come u n Shabbir r sayin that its workin .... in my Borland Compiler its showing 9 Errors & 5 Warnings :eek: .... some of the errors dont even require a compiler - they r glaring sytax errors .... or mebbe I am wrong - mebbe I am using the wrong compiler .... pls do clarify and elaborate in this regard. Thx.

Ciao,
Rajiv :)

shabbir 4Dec2006 10:42

Re: Hangman game source code
 
What I meant good is from code point of view and I never compiled it.

Yup it has some syntax errors and here is the rectification
Code:

#include<conio.h>
#include<string.h>
#include <stdio.h>

main()
{
    char word[30],getit[30],*found;
    int score,loop,len,num,lup,om,luptimes,fitimes,ondtimes,antimes;
    luptimes=0;
    fitimes=0;
    ondtimes=0;
    printf("\n ENTER THE WORD: ");
    gets(word);
    score=0;
    num=0;
    om=0;
   
    len=strlen(word);
    char gname[70];
    printf("\n ENTER YOUR NAME: ");
    scanf("%s",gname);
    char h;
    printf("\n LET's START: ");
    h='_';
    printf("\n LOOK HERE: ");
    for(loop=0;loop!=len;loop++)
    {
        printf("\n %c ",h);
    }
    for(loop=0;loop!=len;loop++)
    {
        om=1;
        num=num+1;
        fitimes=0;
        ondtimes=0;
        printf("\n\n %d LETTER",num);
        scanf("%s",&getit[num]);
        found=strchr(word,getit[num]);
        if(found)
        {
            for(luptimes=0,antimes=1;luptimes!=len;luptimes++,antimes++)
            {
                if(getit[num]==word[luptimes])
                {
                    fitimes++;
                }
                else
                {
                    fitimes=fitimes;
                }
            }
            for(luptimes=num;luptimes!=0;luptimes--)
            {
                if(getit[num]==getit[luptimes])
                {
                    ondtimes++;
                }
                else
                {
                    ondtimes=ondtimes;
                }
            }
            if(fitimes>=ondtimes)
            {
                score=score+1;
                printf("\n OK\n");
                for(lup=0;getit[num]!=word[lup];lup++)
                {
                    om++;
                }
                printf("\n POSITION: %d\n",om);
                printf("\n ===================\n");
            }
            else
            {
                score=score;
                printf("\n NOT AGAIN!\n");
            }
        }
        else
        {
            score=score;
            printf("\n NO\n");
        }
    }
    printf("\n THE WORD IS '%s'\n",word);
    printf("\n YOUR SCORE IS %d OUT OF %d",score,len);
    getch();
    return 0;
}


rai_gandalf 4Dec2006 10:58

3 Errors still remain!
 
There is still an error - the spacing between "ondtime" and "s". Rectify that and the code compiles without errors but with 4 warnings - all of "variable assigned a value but never used" .... But it does work in the way I think it should.

Ciao,
Rajiv

shabbir 4Dec2006 11:20

Re: Hangman game source code
 
The space problem is actually the problem in the algo of parsing the code and not with the actual code.

If you have a line greater than n it will insert a space in between.

Normally that thing does not happen and in normal circumstances you dont have chars after chars without a space.


All times are GMT +5.5. The time now is 19:24.