Created
July 22, 2015 00:17
-
-
Save kingcons/47006ddde2830a0679dd to your computer and use it in GitHub Desktop.
Crash Course for July
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
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