Created
December 2, 2015 18:26
-
-
Save sajoku/e77fbcd6a17626d89e13 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| term = "Star Trek" | |
| guessed_term = "**** ****" | |
| puts "Welcome to the Hangman!" | |
| puts "You are going to guess this movie: " | |
| puts "**** ****" | |
| puts "" | |
| puts "Start with guessing letters, you have in total 3 attempts" | |
| puts "At any times you can also guess the full term!" | |
| puts "So let's start!" | |
| puts "" | |
| print "Input letter: " | |
| attempt_letter = gets.strip | |
| guess_successful = false | |
| term.chars.to_a.each_with_index do |term_letter, index| | |
| # puts "checking position: #{term_letter}, at postition: #{index}" | |
| if term_letter.downcase == attempt_letter.downcase | |
| guessed_term[index] = term_letter | |
| guess_successful = true | |
| end | |
| end | |
| puts "" | |
| puts "" | |
| puts "" | |
| puts "" | |
| puts guessed_term | |
| puts "" | |
| if guess_successful | |
| puts "Your guess was successful!" | |
| else | |
| print "Sorry! Nothing like that. Next: " | |
| end | |
| attempt_letter = gets | |
| guess_successful = false | |
| puts "and so on..." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment