sunjay / turtle

Create Animated Drawings in Rust
http://turtle.rs
Mozilla Public License 2.0
559 stars 54 forks source link

Example: hangman game #231

Closed enaut closed 3 years ago

enaut commented 3 years ago

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

codecov[bot] commented 3 years ago

Codecov Report

Merging #231 (ea891b3) into master (60dba16) will not change coverage. The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #231   +/-   ##
=======================================
  Coverage   61.17%   61.17%           
=======================================
  Files          40       40           
  Lines        2697     2697           
=======================================
  Hits         1650     1650           
  Misses       1047     1047           

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 60dba16...ea891b3. Read the comment docs.

enaut commented 3 years ago

Should all be done now... do these builds also build the examples? Asking because I'd like to stay compatible with everything...

enaut commented 3 years ago

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.

sunjay commented 3 years ago

I was a bit too busy this weekend so I haven't gotten to this yet. Will try to review soon. :)

I did not manage to get the choose function to work without importing the trait... I made this clearer in the comment.

To do this you need to import the choose function, not use the choose method. Run cargo doc --open to see the docs for the turtle::rand module. Unfortunately the version on docs.rs/turtle does not reflect the current API.

Hope that helps!

enaut commented 3 years ago

To do this you need to import the choose function, not use the choose method. Run cargo doc --open to see the docs for the turtle::rand module. Unfortunately the version on docs.rs/turtle does not reflect the current API.

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):

let secret: &str = turtle::rand::choose(WORDS).expect("Failed to choose a random word.");

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.

let secret: &str = turtle::rand::choose(&WORDS.to_vec()).expect("Failed to choose a random word.");
sunjay commented 3 years ago

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 WORDS to &[&str] instead of &[&str; 28] will allow you to use the function version of choose. The method version was essentially coercing to that type anyway. Sorry about that!

sunjay commented 3 years ago

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. :)

enaut commented 3 years ago

New things:

sunjay commented 3 years ago

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! :)

enaut commented 3 years ago

If you want to we could go through this on discord or similar... that might be faster than writing everything...

sunjay commented 3 years ago

Just merged in master. This PR can be merged as soon as the build passes.

enaut commented 3 years ago

Thanks!