Computer Science Canada Help correct my hangman code PLEASE!! |
Author: | Miko99 [ Tue Apr 22, 2003 9:52 am ] | ||
Post subject: | Help correct my hangman code PLEASE!! | ||
Please correct my code. I am lost and do not know what to do!
|
Author: | Blade [ Tue Apr 22, 2003 10:48 am ] |
Post subject: | |
gotta post what you are having trouble with... i looked and id dint find a problem, other than the not being able to guess with uppercase or lowercase... but i dont know if thats what you want.. |
Author: | Miko99 [ Wed Apr 23, 2003 9:01 am ] |
Post subject: | |
My problem is that when i put it a right letter, it reads it as wrong and gives me another body part. WTF is with that? |
Author: | Blade [ Wed Apr 23, 2003 10:48 am ] | ||
Post subject: | |||
Quote: guessedLetters := guessedLetters + guess
mic := "" if guess = mic then put "Nice Job you got a letter" that part right there.... you are comparing guess to mic when mic = the hidden word, up top... i dunno how efficient this is but this is what i'd do..
oh and by the way, this code is an example, it shouldnt work (theres people who discrminate because i give non-working code) |
Author: | Tony [ Wed Apr 23, 2003 11:10 am ] |
Post subject: | |
in blade's example, once the letter is found, the value of i is also character's position. Though I donno why he put that inside the loop |
Author: | Blade [ Wed Apr 23, 2003 11:43 am ] | ||
Post subject: | |||
i put it in a loop because it checks for more than one occurance of the letter... hence index(word(i .. *),pattern) but in his code he doesnt need it... for some reason i was thinking of mine... i used it because i had a boolean array for each of the letters, if the letter was marked as false it would display a "-" if it was marked as true, it would display the correct letter lol so take out the loop, and the subscript of word
|
Author: | Tony [ Wed Apr 23, 2003 4:28 pm ] |
Post subject: | |
thats how I did my hangman too. Boolean array for letters. its just that if you're to look for more then one occurance, instead of having a loop with index, you just continue from the place first match was found. Such as if first match is 10th letter, you dont need to check first 9... just makes it for a more efficient program |
Author: | Blade [ Wed Apr 23, 2003 4:35 pm ] |
Post subject: | |
but if it finds more than one, or two, then you're gonna have to use a loop to check more than once... right? |
Author: | Tony [ Wed Apr 23, 2003 4:38 pm ] |
Post subject: | |
ya, a loop... with exit when counter > length(word) then inside the loop itself you use index(word(counter..*),guess) if that yields a positive result, you guessed another letter and reset the counter to the return value of index. Otherwise you quit the loop. as for the for loop. You might as well just compare individual letters, no point in looking for a match just to see if it was found on first letter. Waste of resourses. |
Author: | Miko99 [ Wed Apr 23, 2003 5:50 pm ] |
Post subject: | |
Ok so can someone show me what to put in to my code to get it working right and where to enter this correction. |
Author: | Blade [ Wed Apr 23, 2003 6:28 pm ] | ||
Post subject: | |||
Quote: if guess = mic then
put "Nice Job you got a letter" instead of if guess = mic then do
you gotta check to see if guess is in the word... you cant compare your guess to your hidden word |