Click here to Skip to main content
14,735,364 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi, im a student so not the most skilled programmer. I am currently making a hangman like game(C#). i have preloaded words onto the game using a list and also have another form for adding more words.

I am trying to figure out a few things, when a random word is picked from the list, how would i go about putting underscores that equal the length of the word. Also, when a guess is made using a text box and guess button, how would i reveal the correct letters in the position.

Also, the words in my game can only be between 4-8 characters, not sure if that makes a difference. Sorry if this is silly.

What I have tried:

All other threads and examples ive seen on the internet haven't been from random words so im not sure where to start tbh.
Posted
Updated 23-Nov-20 4:11am

You can get the length of your words from the String.Length Property (System) | Microsoft Docs[^]. You can check letters by using the String.IndexOf Method (System) | Microsoft Docs[^].
   
The word source doesn't matter - the code you have found presumably works by getting a "starter word" from a user, or a file and then works with that word exclusively. If it doesn't then the code is ... um ... pretty poor as a single word "game" is not going to be any fun after the first time!

So just look at the code where it handles the players responses and see how it deals with them - it should be independent of any actual word content.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900