Created
June 16, 2023 04:37
-
-
Save webgtx/082580c0c62b69feb5a985dfb758dac1 to your computer and use it in GitHub Desktop.
Guess the word
This file contains 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
require "base64" | |
secret_word = Base64.decode64("bGlnaHRzYWJlcg==") | |
player_word = "*" * secret_word.length | |
attempts = 11 | |
puts """ | |
Welcome to the game where you have to guess a word ! | |
secret word has #{secret_word.length} letters, good luck. | |
Becareful, you have only #{attempts} attempts, otherwise you'll lose | |
""" | |
person = { | |
sayhi = def(intel) | |
puts "#{intel} hi" | |
end | |
} | |
person.sayhi("David says: ") | |
secret_word.length.times # 8.times do | |
string += "*" | |
end | |
attempts.times do |attempt| | |
if player_word.index("*") | |
puts """ | |
Attempt ##{attempt} | |
[ #{player_word} ] | |
""" | |
print "Type the word: " | |
guess = gets.chomp | |
idx = secret_word.index(guess) | |
if idx | |
player_word[idx, guess.length] = guess | |
else | |
puts "No luck :(" | |
end | |
else | |
puts "[ #{player_word} ]" | |
puts "Congratulations, you won the game !" | |
exit 0 | |
end | |
end | |
puts "Oh no... You've ran out of your attempts" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment