Skip to content

Instantly share code, notes, and snippets.

@Wonderfall
Created June 15, 2014 17:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Wonderfall/da94280a3017925b1fdd to your computer and use it in GitHub Desktop.
Save Wonderfall/da94280a3017925b1fdd to your computer and use it in GitHub Desktop.
puts "Un simple pendu. On se passera de règles..."
points = 0
loop do
print "Saisissez un mot : "
motMystere = gets.chomp
cache = motMystere.gsub(/./, '_')
30.times { puts }
loop do
puts cache
print "Proposez une lettre : "
proposition = gets.chomp
if motMystere.include?(proposition)
p = motMystere.index(proposition)
cache[p] = motMystere[p]
until motMystere.index(proposition, p+1) == nil do
p = motMystere.index(proposition, p+1)
cache[p] = motMystere[p]
end
end
if cache == motMystere
puts "Bien joué ! Le mot était #{motMystere} !"
points += 20
2.times { puts }
break
else
points -= 1
puts
end
end
print "Rejouer ? (o/n) "
if gets.chomp == 'n'
break
else
2.times { puts }
end
end
at_exit { puts "Votre score est : #{points}" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment