Hangman- different problem>
Author |
Message |
sweet4evr
|
Posted: Fri Apr 11, 2008 3:57 pm Post subject: Hangman- different problem> |
|
|
i have allready looked into other posts and have not found my answer yet.
I am creating a hangman game and so far i have asked the user to enter a phrase and a
clue and have drawn the gallow section.
The problem i am having is that under the gallows section i have to display the blank phrase line and everytime the person enters a good guess, the screen changes and says " Good guess" and if not, it displays the wrong guesses at the top right corner.
I cannot do any of these last things although i have an idea.
Should using a case statement help me any or do i go for the for loop and how? |
|
|
|
|
|
Sponsor Sponsor
|
|
|
A.J
|
Posted: Fri Apr 11, 2008 7:47 pm Post subject: Re: Hangman- different problem> |
|
|
every time you get a letter, u check the index of it in the hidden word
for example, if the hidden word is 'strawberry' and the person guesses 't' then this
is what you would do:
Turing: |
var word: ="strawberry"
var letter : char
get letter
if index (word,letter ) not= 0 then
put "Good guess"
else
put "Bad guess"
end if
|
the 'index' function returns the position of a letter or sequence of letters in a word.
so index('strawberry','t') returns 2 since 't' is the 2nd letter of the word 'strawberry'.
but index('strawberry','x') returns 0 since 'x' isn't found in the word 'strawberry'.
as for the blanks, just draw lines beside each other to indicate blanks where the letters should go.
sry if this doesn't help since I have other work to do |
|
|
|
|
|
|
|