-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Example: hangman game #231
Conversation
working so far: drawing the hangman, drawing the lines for a constant password.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking the time to put this together @enaut! Looking forward to reviewing in more detail once you're ready. Given that #22 and #60 won't be ready any time soon, let's stick to using the terminal for text input and output for now. I don't think #226 should be used outside of that example.
The player can have a terminal window side by side with the turtle window while they guess. I think it's still a great example even with that limitation. Very cool that you've used multiple turtles to divide up the drawing! 😁
Regarding your list:
- writing letters onto the lines
Let's print the lines into the terminal for now. We can still draw them on the screen too. Maybe we can draw an X or some other symbol to indicate letters they've gotten right (while also printing something useful in the terminal).
- getting input (probably possible by listening to keyboard events?)
Let's prompt for input in the terminal by printing something like "Enter your guess:" and then doing something with the letter they pick. You can also potentially use keyboard events for this. I'll leave it up to your creativity. :)
- draw hangman step on error
I see you've already got a list of every step, so you should be able to go through them and draw the next one every time there is an error.
- draw letter on correct guess
As I said above, let's try drawing some other symbol for correct letters and use the terminal for printing the text.
- loose on the last hangman step
Maybe we can draw a big sad face across the turtle window when this happens or something.
- win on all letters guessed right
Idea: Big smiley face or having the turtle run around the screen? Again, I'll leave that up to you.
- make the secret a random word
Since this is just an example for this crate, let's leave it as a hard-coded word in a variable like you currently have. There's no word list modules in Rust as there are in Python, so I think it's fine just to choose the simpler option for this. If this was a full hangman app (outside of this repo), I'd recommend using a crate that gives us similar word lists as there are in Python.
Let me know if you need any help! Thanks for working on this! 😁 🎉
* green dots for correctly guessed letters * input via terminal * react to correctly or wrongly guessed letters * react to win or loose * add a small worlist to randomly choose from
Should all be done now... do these builds also build the examples? Asking because I'd like to stay compatible with everything... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work @enaut! 🎉 I will review this in more detail over the next few days, but I've left a few cursory comments of things I noticed while quickly going through the code.
For my full review I'll check out your code locally and spend some time running the example to see what it's like. I'll also look closer at each line of code to see if there are any other things we can improve. Looking forward to playing hangman! 😁
Feel free to keep making changes/improvements, and let me know when you're ready to go again. Happy to answer any questions you may have. Thanks for putting in all the effort to get this working! :)
Sorry I could have sworn I tested it... but obviously i forgot to save or something... I did not manage to get the choose function to work without importing the trait... I made this clearer in the comment. |
I was a bit too busy this weekend so I haven't gotten to this yet. Will try to review soon. :)
To do this you need to import the Hope that helps! |
This is what I did... however that would require &str to implement Random (at least the compiler says so...) which cannot be done because str is not fixed size. the not working lines are (tried in different permuttations):
The only way I managed to get this working is by creating a vec from the fixed size array and choose from that - I dislike that and find my original solution much cleaner.
|
Ooo looks like there is a bug on the random slice implementations for fixed sized arrays that is forcing the type stored in the array to implement Random. I'll fix that shortly. In the meantime changing the type of |
I just merged in #236 with the fix so if you rebase you may not even need to change the type in order to use the function. Let me know if you run into any further issues. :) |
New things:
|
Hey! Really sorry for not getting to your PR yet. Going through some things and will try to find time soon. I usually try to be really quick with these things, but it unfortunately didn't work out this time. I will get to this! :) |
If you want to we could go through this on discord or similar... that might be faster than writing everything... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work @enaut! I checked out the code locally and really enjoyed playing hangman. Sorry the review took so long! Appreciate you working with the current input/text rendering limitations of turtle and making this anyway.
Just need to update to the latest master branch and this should be good to go.
Just merged in master. This PR can be merged as soon as the build passes. |
Thanks! |
working:
I think I have a rough idea about how to solve the non bold ones... the bold ones I could only do by "stealing" from the other pull request (#226).
references: #227
things would be much nicer if #22 and #60 would be implemented