Skip to content

Instantly share code, notes, and snippets.

@webgtx
Created June 16, 2023 04:37
Show Gist options
  • Save webgtx/082580c0c62b69feb5a985dfb758dac1 to your computer and use it in GitHub Desktop.
Save webgtx/082580c0c62b69feb5a985dfb758dac1 to your computer and use it in GitHub Desktop.
Guess the word
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