Skip to content

Instantly share code, notes, and snippets.

@kingcons
Created July 22, 2015 00:17
Show Gist options
  • Save kingcons/47006ddde2830a0679dd to your computer and use it in GitHub Desktop.
Save kingcons/47006ddde2830a0679dd to your computer and use it in GitHub Desktop.
Crash Course for July
require 'pry'
words = [
"buffalo", "sportscar", "coffee", "snazzy",
"childish", "futile", "authoritarian", "fantastic",
"beautiful", "building", "macintosh", "airport"
]
answer = words.sample
turn_count = answer.length
guesses = []
puts "Welcome to Hangman!"
binding.pry
def win?(answer, guesses)
win = true
binding.pry
answer.chars.each do |char|
unless guesses.include?(char)
win = false
end
end
win
end
def loss?(turn_count)
turn_count.zero?
end
until win?(answer, guesses) || loss?(turn_count)
puts "You've guessed: #{guesses}"
puts "Pick a letter!"
letter = gets.chomp
guesses << letter
unless answer.include?(letter)
turn_count = turn_count - 1
end
end
if win?(answer, guesses)
puts "Good job. You won!"
else
puts "Sorry, you lost. The word was: #{answer}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment