
-----------------------------------
limpex
Thu Dec 18, 2008 9:06 pm

Need help with strings!
-----------------------------------
Hey there guys. I need a help with this hangman program. This is what I need to do, you type in a secret word and print an "*" for the letters in word. Then you ask the user for a letter. If the letter is correct, it should replace in the "*"s. If the letter in incorrect, it shows 'invalid. Finally, I need to tell the guesses it took to guess the word.

How do I replace the letter in the "*"? I am very new at strings and don't know much. Can any one fix my program? Thank You.


var word : string
var option : int
var letter : string
var d3lay : string (1)


put "--HANGMAN GAME MENU--"
put "1) New Word"
put "2) Quit Game"
put " "
put "Player 1 - Choose an option: " ..
get option

if option = 1 then
    cls
    put "Player 1 - Choose a word: " ..
    get word
    cls

    var newword : array 1 .. length (word) of string
    for i : 1 .. length (word)
        put "-" ..
    end for
    put " "

    loop
        put "Player 2 - The word has ", length (word), " letter(s). Choose a letter: " ..
        get letter
        if index (word, letter) = 0 then
            put letter, " is not in the word."
        else
            put "You found a letter!"
        end if
        put " "
        put "Hit any key to continue --->" ..
        getch (d3lay)
        cls
    end loop


elsif option = 2 then
    cls
    put "Thanks for playing!"
end if 

Mod Edit: Remember to use syntax tags! Thanks :) [syntax="Turing"]Code Here[/syntax]

-----------------------------------
TheGuardian001
Thu Dec 18, 2008 10:45 pm

Re: Need help with strings!
-----------------------------------
I'm assuming that what you want for the Asterisks is to make it so that the letters being typed can't be seen by other people, like in a password field.

the first thing you will need to do this is:


View.Set("noecho")


this will set the output window to not print a character when a key is pressed (remember, you want to put this AFTER they enter option 1 or 2, otherwise they won't see what they have entered.
you can cancel out the noecho statement with:

View.Set("echo")


now that the program no longer outputs what the user enters, all you need to do is print out the "*" every time they press a button while entering the word (although if you do use this method, you will need to get the word one character at a time, instead of as a string)

for guesses it took to take the word, simply use an integer variable. Start it at 0, and every time they guess a letter, increase it by one until they get the whole word
