1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Hangman game source code

Discussion in 'Game Programming' started by TEJUS, Aug 9, 2006.

  1. TEJUS

    TEJUS New Member

    Joined:
    Aug 6, 2006
    Messages:
    11
    Likes Received:
    1
    Trophy Points:
    0
    Occupation:
    STUDENT
    Location:
    IN KERALA,KOLLAM
    Hangman game source code for you.
    ============
    ----HANGMAN----
    ============​
    Code:
    #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;
    }
     
  2. TEJUS

    TEJUS New Member

    Joined:
    Aug 6, 2006
    Messages:
    11
    Likes Received:
    1
    Trophy Points:
    0
    Occupation:
    STUDENT
    Location:
    IN KERALA,KOLLAM
    Why No One Is Replying ?
     
  3. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,285
    Likes Received:
    364
    Trophy Points:
    83
    What you want in reply?
     
  4. TEJUS

    TEJUS New Member

    Joined:
    Aug 6, 2006
    Messages:
    11
    Likes Received:
    1
    Trophy Points:
    0
    Occupation:
    STUDENT
    Location:
    IN KERALA,KOLLAM
    i want to know wheter my program is good?
     
  5. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,285
    Likes Received:
    364
    Trophy Points:
    83
    Yup its a good one I must say.

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

    shailender0435 New Member

    Joined:
    Dec 1, 2006
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    hey iam getting an error
    undefined symbol_main in module c).ASM
     
  7. rai_gandalf

    rai_gandalf New Member

    Joined:
    Nov 4, 2005
    Messages:
    46
    Likes Received:
    1
    Trophy Points:
    0
    Occupation:
    Final Year Comp Engg
    Location:
    Mumbai
    Home Page:
    9 Errors and 5 Warnings!! Whats this?!


    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 :)
     
  8. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,285
    Likes Received:
    364
    Trophy Points:
    83
    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;
    }
    
     
  9. rai_gandalf

    rai_gandalf New Member

    Joined:
    Nov 4, 2005
    Messages:
    46
    Likes Received:
    1
    Trophy Points:
    0
    Occupation:
    Final Year Comp Engg
    Location:
    Mumbai
    Home Page:
    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
     
  10. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,285
    Likes Received:
    364
    Trophy Points:
    83
    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.
     
  11. rai_gandalf

    rai_gandalf New Member

    Joined:
    Nov 4, 2005
    Messages:
    46
    Likes Received:
    1
    Trophy Points:
    0
    Occupation:
    Final Year Comp Engg
    Location:
    Mumbai
    Home Page:
    oh! didnt know that .... alright then, that settles it.

    Ciao,
    Rajiv
     
  12. Peter_APIIT

    Peter_APIIT New Member

    Joined:
    Apr 11, 2007
    Messages:
    92
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Student
    Location:
    Malaysia
    Hello everyone, what is hangman? Sorry for my sutpidness.

    Thanks for oyur explanations.
     
  13. h4rapture

    h4rapture New Member

    Joined:
    Nov 26, 2007
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hi I am doing a research project on a hangman program for C++ and i stumbled across this, I was wondering if someone could explain the different variables to me. I did not fully understand this. I am still in the entry levels of programming and I need to learn what variable does what for my class.

    int score,loop,len,num,lup,om,luptimes,fitimes,ondtimes,antimes;

    thanks :)
     
  14. wolverine

    wolverine New Member

    Joined:
    Nov 28, 2007
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hello i am Knew to the forum and I am trying to write a hangman game for 2 players. I want to begin with a menu of 3 choices. New game, high scores and exit. If the player press the first, the game will start and ask for the “Word” .After that will scan the word. It will ask for how many wrong letters can the other player write. As a default will have 7. Every time it will ask for given word or letter. With an algorithm will compute the high scores.It Will store the names and the scores to a file if the player choose to see the high scores with the second option . Can anyone help me how to do that.
    Thanks!
     
  15. oogabooga

    oogabooga New Member

    Joined:
    Jan 9, 2008
    Messages:
    115
    Likes Received:
    11
    Trophy Points:
    0
    For a beginner, any program that runs correctly is great.
    But to learn proper style you need to study how good programs are written.
    Good style consists of such things as:
    * dividing a program up into subroutines (functions in C)
    * not using more variables than you absolutely have to
    * giving your variables informative names so readers don't have to figure out what they're for.
    * comments are also useful, especially for non-trivial things (don't just say what a simple line of code does in English, that's just for textbook examples).

    Also, some ascii graphics couldn't hurt!
    Code:
      ______
      |    |
      |    O
      |   /-\
      |    |
      |   /-\
     
    Last edited: Jan 16, 2008
  16. skp819

    skp819 New Member

    Joined:
    Dec 8, 2008
    Messages:
    89
    Likes Received:
    3
    Trophy Points:
    0
    you should explain some thing about your program.
    you should use some comment to explain you program working.
     
  17. Erol

    Erol New Member

    Joined:
    Jun 23, 2009
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hi guys ,I have just done my C# hangman program.If somebody needs that send me an e-mail.Thanks Erolaktekin@hotmail.com
     
  18. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,285
    Likes Received:
    364
    Trophy Points:
    83
    If you really want to share the code why not post them here in the forum for others to see it.
     
  19. akanglil

    akanglil New Member

    Joined:
    Jun 25, 2009
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Home Page:
    where's a code?
     
  20. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,285
    Likes Received:
    364
    Trophy Points:
    83

Share This Page