Hi there,

I'm making a Hangman game and stuck on this part:

public void Game(string letter)
                int index = word.IndexOf(letter);

I am testing whether my string variable word contains a letter. If it does, it gets the index. (Yep, I used the IndexOf class) Now what I want to dos is to change a label that's on my form from _ _ _ _ _ to, for example, A _ _ _ _ where the word is actually APPLE.

In the class, I randomly select a word from an array, and put that word in a string called word. Then I set the label on my form from it's initial value "" which is nothing to a bunch of underscores, depending of course how big the word is. So if the random word is for example: Earth, then the label on the form would look like this: _ _ _ _ _.

So again, how would I go about changing the same index of the label as to the word(that's if the letter is in the word).


7 Years
Discussion Span
Last Post by Momerath

Just one think: What will happen with characters P in your case? There are two P letters in your word, so which index will be chosen for it?
This is not a good way to contiune. Just to make you think a bit better.


This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.