Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Hangman please help

Author
Message
New Student
18
Years of Service
User Offline
Joined: 4th Oct 2006
Location:
Posted: 28th Nov 2006 20:08
Hello,

I am having difficulty trying to end my hangman game. I need the body parts to show up when wrong letters are guessed. I have the correct letters showing up when guessed correctly. I just can't seem to implement the body part functions to show up.

Please Help.


"For God so loved the world, that He gave his only begotten Son, that whosoever believeth in him shall not
perish, but have everlasting life. John 3:16
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 28th Nov 2006 23:31
Instead of making separate functions for each body part put it into one function with a "select" statement. Outside of the function you "inc error" then call the function with "WrongGuess(error)" to draw each part in the order you want them drawn.

New Student
18
Years of Service
User Offline
Joined: 4th Oct 2006
Location:
Posted: 29th Nov 2006 00:42
So, how do I implement to have each body part to show up individually as the letter is guessed wrong. So, if the correct letter is "a" and the player types in "b", I would like for the
head to show up, then another letter guessed wrong then the body
shows up, and so forth. I am trying to put it in a for/next loop?

Please advise.

Thanks.

"For God so loved the world, that He gave his only begotten Son, that whosoever believeth in him shall not
perish, but have everlasting life. John 3:16
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 29th Nov 2006 07:17
I hope this message doesn't insult you but first you don't really need to separate each letter into another array.

Your code:


The above isn't needed because you have the string already in "almost$". You can look at the string itself to see if the letter guessed by the player is in "almost$"... I'll go over this later though.


This next part that creates the blank lines can be put into one function.

Your code:


One function with simple if/then statements lower the amount of code because it's not repeated within separate functions.



Putting an input outside of the while/endwhile and repeating that input before the endwhile isn't needed because you can simply put the input inside the while/endwhile.

Your code:




In the above code notice the command under "input". When you search strings it's case sensitive... "A" and "a" are two different letters. The command "lower$(string$)" forces the user input to be lowercase... since all your words are lowercase they will always match letters the user types in (unless the user types more than one letter at a time).

Next is the fun part.

Your code:


Since the "letterpart$()" array is not there anymore you're probably asking how do you check the string for a letter?... basically how you did it to separate the letters into the array but a little differently. You want a for/next loop that starts at 1 and ends at "len(almost$)" (there's no need to make a variable to store the length of the string because of that command). To check the letter you use an if/then looking for "mid$(almost$,fornextvariable)". To get the routine to work right you need a switch. It's just like the light switches at your house... it's either on or it's off. You make the switch in code by defining a variable and make it equal zero (which means off) and if a certain thing happens the switch is turned on (something other than zero... usually 1 at first). After the routine you check to see if the switch is on or off (still a zero or a one) to determine what to do.

In your program you start the switch at zero which represents no letters found. When a letter is found you turn the switch on, increase "yes" for a right answer, and write the letter to the screen. After all the letters in the "almost$" have been looked at you check to see if the switch is still off (no letter has been found). If the switch is still at zero you increase the variable "error" and call the function "WrongGuess(error)"... when error=1 the head is drawn... when error=2 the body is drawn and so forth.

When you have an if/then like you have at the bottom of the above code snip... if you don't have anything "else" for it to do then take it out the "else". Also there's no need to check if all the letters have been guessed within the for/next loop. It's better to move it outside of the for/next loop.

The last thing that you had that's not a good idea to do is have regular code at the end. The regular code should end before the functions. Move "endofprogram: end" to before your first function.

Here's your complete code with changes:


Don't be afraid to space out your code. Spacing is easier on the eyes and makes it easier to debug. Indenting code also helps. I indent with a single space to the right of any loop so I can see where the loop begins and ends. Some people use tabs but a space is enough for me.

One of the things I didn't put in (so you have something to do) is a way to check if a letter has been guessed already. If a person puts in the same letter (that's in the string) over and over again they'll eventually win because "yes" will eventually equal the length of the string. I'm right here if you need help.
New Student
18
Years of Service
User Offline
Joined: 4th Oct 2006
Location:
Posted: 29th Nov 2006 20:48
Hi Grog,

Thank you so much. I never learned the "inc" code before. I will assume that means incorporate. I am very new at this at you can see. It seems like there are so many ways this game can be done, it's just knowing how to implement them.

Okay, so I am going back to fix the errors I have with the help
you gave me. Again, thank you, you rock and I truly appreciate the time and effort you took out to help me.


"For God so loved the world, that He gave his only begotten Son, that whosoever believeth in him shall not
perish, but have everlasting life. John 3:16
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 29th Nov 2006 21:28
Np. "inc" means to increase. If you use "inc a" it's the same as "a=a+1"... "inc a,10" is the same as "a=a+10". "dec" means to decrease.

Technically the help files say "inc" means increment and "dec" means decrement... but it still means the same as "increase" and "decrease".

That's what I love about programming. You can do something totally different in code and still have the same results on the screen.

Login to post a reply

Server time is: 2024-11-26 05:47:29
Your offset time is: 2024-11-26 05:47:29