Thread: Help with hangman game.

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    5

    Smile Help with hangman game.

    Well, I'm making a hangman game. Can you help me on how I can replace the word with asterisks? Thanks

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Write all of it except for the substitution part. Get it so you can enter letters and find out if they are in the word you are looking for, once you have that done, it should be pretty easy to substitute out letters.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Mar 2011
    Posts
    5
    What is the substitution part?

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Fill an array with as many * as there are letters in the word. When a letter is matched, go to that spot and replace the * with the letter.


    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Registered User
    Join Date
    Mar 2011
    Posts
    5
    Oh! Thanks But I've put this in my code, is this correct?

    k=strlen(words[j]);
    for(l=0;l<k;l++){
    printf("*");
    }
    printf("\n");


    where words[j] is the word the user will guess. Did I replace the word with asterisks correctly?

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You need to use code tags if you post code. All you are doing is showing *, not actually placing them in an array anywhere. While I suppose you could get by with your way, it would be more cumbersome than just putting them in an array.

    Quzah.
    Hope is the first step on the road to disappointment.

  7. #7
    Registered User
    Join Date
    Mar 2011
    Posts
    5
    Hmm. I've found this:
    j = strlen(name);
    for(; k<j ; k++)
    {
    guess[k]='*';
    }
    but it doesn't seem to work on my code

  8. #8
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    char word[] = "secret";
    char guess[ BUFSIZ ] = {0};
    Copy 7 * into 'guess'.
    Every time there is a letter guessed, run through each character in 'word', and see if it matches. If it does, replace that * with the guessed letter.


    Quzah.
    Hope is the first step on the road to disappointment.

  9. #9
    Registered User
    Join Date
    Mar 2011
    Posts
    5
    Thanks!)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Event driven game engine
    By abachler in forum Game Programming
    Replies: 9
    Last Post: 12-01-2009, 06:03 AM
  2. Confused Beginner - hangman game
    By goodfornothing in forum C++ Programming
    Replies: 4
    Last Post: 11-30-2009, 11:06 PM
  3. Replies: 15
    Last Post: 10-20-2009, 09:39 AM
  4. craps game & dice game..
    By cgurl05 in forum C Programming
    Replies: 3
    Last Post: 03-25-2006, 07:58 PM
  5. hangman game, copied staight from book.. 31 errors?!?!?!?!
    By Blizzarddog in forum C++ Programming
    Replies: 10
    Last Post: 10-25-2002, 12:20 AM