Help a noobie out with a simple hangman
Hi! New to coding and I need some help to solve this problem.
Shall I save the words to a list? Any help appreciated. Thanks!
17 Replies
What did you already do? Do you have a plan or idea how to solve this problem?
This is what I've done so far. Don't have a plan (yet 🥲 )
I figure depending what word Im guessing there is a different outcome
Maybe you could try splitting that game into multiple simple steps and plan accordingly. Don't worry about how to implement those yet.
As an example
1. Define the word to guess
2. Define the alphabet permutation to use
3. ???
You already got the first two steps.
Thanks! I figure I could do a for loop that increments over the attempts, with a maximum of 10 attempts
That sounds like a good start.
The question now would be. What will happen if the letter is in your word and what if it isn't.
Then you basically got it.
Thanks, I think I got it! Almost 😄
Looks great.
A string is just a collection of chars. So you can itterate over a string like any other collection.
You are already doing that. What you need is a way to check if something is a member of a collection.
Thanks alot!
This is my final result
Looks like it should work, did you test it? Good job!
A few technical points you could maybe improve if you are interested.
Your assignment said, that the guessedWord should not be longer than 16 letters. You could check for that.
Connected to that. Your ReadLines show warnings. Maybe you could look at those and adress them.
Besides this assignment. Maybe you could try generating the permutation of the alphabet yourself instead of having that as an input?
I can also think of a more advanced solution to this problem, in which you wouldn't need to iterate over the string.
Do you know what a HashSet is? If not don't worry about it for now!
Yes, I did test it and it worked. Thank you for your input, I will look it up later 😄 I do not know what a hashset is
I'm on another assignment now and it's far more worse
Just break it down into simple small steps again and then try to implement them. You got the last one without me having to tell you anything.
Hey I don't have time to read the full context and status of this thread, but I just want to mention that I have an example of a console Hangman game on GitHub if seeing my example may help. If you would like a link to it just ask.
Thank you very much! I got some good help from Joschi. Very kind of you though 😄